Tuesday, 3 February 2015

Function template

Function template

A function template defines a family of functions.

Syntax

template < parameter-list > function-declaration (1)
export template < parameter-list > function-declaration (2)  



Explanation

function-declaration - a function declaration. The function name declared become a template name.
function-declaration-with-placeholders - a function declaration where the type of at least one parameter uses the placeholder auto or a constrained type specifier: the template parameter list will have one invented parameter for each placeholder.
parameter-list - a non-empty comma-separated list of the template parameters, each of which is either non-type parameter, a type parameter, a template parameter, or a parameter pack of any of those.


Example :

void f(auto (auto::*)(auto)); // #1
template<typename T, typename U, typename V> void f(T (U::*)(V)); // same as #1
 
template<int N> void f(Array<auto, N>*); // #2 (assuming Array is a class template)
template<int N, typename T> void f(Array<T, N>*); // same as #2
 
void g1(const C1*, C2&); // #3 (assuming C1 and C2 are concepts
template<C1 T, C2 U> void g1(const T*, U&); // same as #3

No comments:

Post a Comment