c++ - "typename qualified-id" referring to a type in a non-type parameter-declaration -
14.1 [temp.param], paragraph 2
...
typename
followed unqualified-id names template type parameter.typename
followed qualified-id denotes type in non-type parameter-declaration...
i'm bit confused meaning of bold text. specifically, typename
can occur in 2 different contexts (type-specifier or template-parameter), 1 refer to?
for former case, considered:
struct { struct x { }; int x; }; struct b { struct x { }; }; template<class t> void f(t t) { typename t::x x; // t can or b }
however, neither
a::x
norb::x
non-type parameter-declaration (they member-declarations).for latter case, i'm not sure why that's necessary. why not directly write down type qualified-id? parameterization necessary?
this about
struct s { typedef int x; }; template <typename t, typename t::x> void f() { } int main() { f<s, 1>(); }
here, typename t
means t
named template type parameter, typename t::x
type of unnamed non-type template parameter.
type-parameter syntax used template type parameters, parameter-declaration syntax used template non-type parameters.
typename t
cannot parsed typename-specifier in parameter-declaration, lacks nested-name-specifier, must type-parameter.
typename t::x
cannot parsed type-parameter, allows single identifier after typename
keyword, must parameter-declaration.
i think there's no ambiguity, text clarifies how differently these 2 template-parameters parsed.
Comments
Post a Comment