Non-type template parameters (C++ only)
The syntax of a non-type template parameter is the same
as a declaration of one of the following types:
- integral or enumeration
- pointer to object or pointer to function
- lvalue reference to object or lvalue reference to function
- pointer to member
std::nullptr_t
template<int a[4]> struct A { };
template<int f(int)> struct B { };
int i;
int g(int) { return 0;}
A<&i> x;
B<&g> y;The type of &i is int
*, and the type of &g is int
(*)(int).You can qualify a non-type template parameter with const or volatile.
You cannot declare a non-type template parameter as a floating point, class, or void type.
Non-type non-reference template parameters are not lvalues.