A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://timsong-cpp.github.io/cppwp/n4140/temp.arg.nontype below:

[temp.arg.nontype]

14.3.2 Template non-type arguments [temp.arg.nontype]

A template-argument for a non-type, non-template template-parameter shall be one of:

Note: A string literal ([lex.string]) does not satisfy the requirements of any of these categories and thus is not an acceptable template-argument. [ Example:

template<class T, const char* p> class X {
  
};

X<int, "Studebaker"> x1;        
const char p[] = "Vivisectionist";
X<int,p> x2;                    

 — end example ]  — end note ]

Note: Addresses of array elements and names or addresses of non-static class members are not acceptable template-arguments. [ Example:

template<int* p> class X { };

int a[10];
struct S { int m; static int s; } s;

X<&a[2]> x3;                    X<&s.m> x4;                     X<&s.s> x5;                     X<&S::s> x6;                    

 — end example ]  — end note ]

Note: Temporaries, unnamed lvalues, and named lvalues with no linkage are not acceptable template-arguments when the corresponding template-parameter has reference type. [ Example:

template<const int& CRI> struct B {  };

B<1> b2;                        
int c = 1;
B<c> b1;                        

 — end example ]  — end note ]

The following conversions are performed on each expression used as a non-type template-argument. If a non-type template-argument cannot be converted to the type of the corresponding template-parameter then the program is ill-formed.

Example:

template<const int* pci> struct X {  };
int ai[10];
X<ai> xi;                       
struct Y {  };
template<const Y& b> struct Z {  };
Y y;
Z<y> z;                         
template<int (&pa)[5]> struct W {  };
int b[5];
W<b> w;                         
void f(char);
void f(int);

template<void (*pf)(int)> struct A {  };

A<&f> a;                        

 — 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