c++11 - C++ parameter pack fails to expand -
i'm playing variadic templates , can't understand why following code won't compile (gcc 4.9.2 std=c++11):
it's example, need similar kind of use in code , fails well:
template<int i> class type{}; template<typename ... tlist> class a{ public: template<int ...n> void a(type<n> ... plist){ } }; template<typename ... tlist> class b{ public: template<int ... n> void b(type<n> ... plist){ a<tlist...> a; a.a<n...>(plist ...); } };
and use example:
b<int, int, int> b; b.b<1,7,6>(type<1>(),type<7>(),type<6>());
i following error:
file.cpp: in member function ‘void b<tlist>::b(type<n>...)’: file.cpp:58:9: error: expected ‘;’ before ‘...’ token a.a<n...>(plist ...); ^ file.cpp:58:24: error: parameter packs not expanded ‘...’: a.a<n...>(plist ...); ^ file.cpp:58:24: note: ‘n’
however following code compiles fine (i removed tlist parameters both classes , adjusted code accordingly):
template<int i> class type{}; class a{ public: template<int ...n> void a(type<n> ... plist){ } }; class b{ public: template<int ... n> void b(type<n> ... plist){ a; a.a<n...>(plist ...); } }; b b; b.b(type<1>(),type<7>(),type<6>());
can give me explanation? thanks.
the compiler has no reason believe a.a
template; such, mandated interpret <
less-than operator. write:
a.template a<n...>(plist ...); ^^^^^^^^^
in second example, knows a.a
template, because type of a
there not depend on template parameter.
Comments
Post a Comment