Presentation is loading. Please wait.

Presentation is loading. Please wait.

when it needs to be done at compile-time

Similar presentations


Presentation on theme: "when it needs to be done at compile-time"— Presentation transcript:

1 when it needs to be done at compile-time
Metaprogramming when it needs to be done at compile-time

2 Metaprogramming programming to be executed at compile-time
in C++ done with templates, hence template metaprogramming (TMP) optimizes code at compile-time, possibly faster compilation is slower some programming work is delegated to compiler resultant code is easier(?) to understand

3 Preliminaries decltype(expression) – returns type of expression, C++11 addition recursive template – a template may be invoked inside the template stopping case provided as specialization non-type parameter for template instantiation – used for template recursion treated as a constant std::function is defined in <functional> is used to create function types, to be used as template parameters syntax std::function<returnValueType (argTypes…)> example std::function <void(int, const string&)> f1 = func;

4 Template Specialization
may need to implement specific actions for particular type specialization – overrides generic classes or method may specialize either whole template template<> class Stack<char, 100> { }; or individual methods void Stack<char>::input(){…} why not use non-templated classes for specific types? specialization provides uniform interface to template users may only need specialization on individual methods

5 Examples branching factorial loop unrolling


Download ppt "when it needs to be done at compile-time"

Similar presentations


Ads by Google