There is no semantic difference between class and typename in a template-parameter. typename followed by an unqualified-id names a template type parameter. typename followed by a qualified-id denotes the type in a non-type 137 parameter-declaration. A storage class shall not be specified in a template-parameter declaration. Types shall not be defined in a template-parameter declaration. [ Note: A template parameter may be a class template. For example,
template<class T> class myarray { }; template<class K, class V, template<class T> class C = myarray> class Map { C<K> key; C<V> value; };
— end note ]
A non-type template-parameter shall have one of the following (optionally cv-qualified) types:
integral or enumeration type,
pointer to object or pointer to function,
lvalue reference to object or lvalue reference to function,
pointer to member,
std::nullptr_t.
[ Note: Other types are disallowed either explicitly below or implicitly by the rules governing the form of template-arguments ([temp.arg]). — end note ] The top-level cv-qualifiers on the template-parameter are ignored when determining its type.
A non-type non-reference template-parameter is a prvalue. It shall not be assigned to or in any other way have its value changed. A non-type non-reference template-parameter cannot have its address taken. When a non-type non-reference template-parameter is used as an initializer for a reference, a temporary is always used. [ Example:
template<const X& x, int i> void f() { i++; &x; &i; int& ri = i; const int& cri = i; }
— end example ]
A non-type template-parameter shall not be declared to have floating point, class, or void type. [ Example:
template<double d> class X; template<double* pd> class Y; template<double& rd> class Z;
— end example ]
A non-type template-parameter of type “array of T” or “function returning T” is adjusted to be of type “pointer to T” or “pointer to function returning T”, respectively. [ Example:
template<int* a> struct R { }; template<int b[5]> struct S { }; int p; R<&p> w; S<&p> x; int v[5]; R<v> y; S<v> z;
— end example ]
The set of default template-arguments available for use with a template declaration or definition is obtained by merging the default arguments from the definition (if in scope) and all declarations in scope in the same way default function arguments are ([dcl.fct.default]). [ Example:
template<class T1, class T2 = int> class A; template<class T1 = int, class T2> class A;
is equivalent to
template<class T1 = int, class T2 = int> class A;
— end example ]
If a template-parameter of a class template or alias template has a default template-argument, each subsequent template-parameter shall either have a default template-argument supplied or be a template parameter pack. If a template-parameter of a primary class template or alias template is a template parameter pack, it shall be the last template-parameter. A template parameter pack of a function template shall not be followed by another template parameter unless that template parameter can be deduced from the parameter-type-list of the function template or has a default argument ([temp.deduct]). [ Example:
template<class T1 = int, class T2> class B; template<class... T, class... U> void f() { } template<class... T, class U> void g() { }
— end example ]
A template-parameter shall not be given default arguments by two different declarations in the same scope. [ Example:
template<class T = int> class X; template<class T = int> class X { };
— end example ]
When parsing a default template-argument for a non-type template-parameter, the first non-nested > is taken as the end of the template-parameter-list rather than a greater-than operator. [ Example:
template<int i = 3 > 4 > class X { }; template<int i = (3 > 4) > class Y { };
— end example ]
A template-parameter of a template template-parameter is permitted to have a default template-argument. When such default arguments are specified, they apply to the template template-parameter in the scope of the template template-parameter. [ Example:
template <class T = float> struct B {}; template <template <class TT = float> class T> struct A { inline void f(); inline void g(); }; template <template <class TT> class T> void A<T>::f() { T<> t; } template <template <class TT = char> class T> void A<T>::g() { T<> t; }
— end example ]
If a template-parameter is a type-parameter with an ellipsis prior to its optional identifier or is a parameter-declaration that declares a parameter pack ([dcl.fct]), then the template-parameter is a template parameter pack ([temp.variadic]). A template parameter pack that is a parameter-declaration whose type contains one or more unexpanded parameter packs is a pack expansion. Similarly, a template parameter pack that is a type-parameter with a template-parameter-list containing one or more unexpanded parameter packs is a pack expansion. A template parameter pack that is a pack expansion shall not expand a parameter pack declared in the same template-parameter-list. [ Example:
template <class... Types> class Tuple; template <class T, int... Dims> struct multi_array; template<class... T> struct value_holder { template<T... Values> struct apply { }; }; template<class... T, T... Values> struct static_array;
— end example ]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4