c++ - Why don't default-template arguments work on using declarations? -
i'm trying search alternative following dilemma. know how when have template class/function default template-argument have apply angle brackets when they're empty? attempt @ making fix. know can use simple typedef
(typedef x<> l
) don't want use different names refer class.
so tried following. reason when supply type template argument still doesn't work. why that?
#include <type_traits> template <typename = void> struct x {}; template <typename t = void> using l = typename std::conditional< std::is_void<t>::value, x<>, x<t> >::type; int main() { l l; }
errors:
prog.cpp: in function ‘int main()’:
prog.cpp:10:7: error: missing template arguments before ‘l’
prog.cpp:10:7: error: expected ‘;’ before ‘l’
the syntax same other type templates: need provide empty template brackets default templates:
l<> l;
the using
declaration redundant since conditional
inside nothing – you remove it, yielding template <typename t = void> using l = x<t>;
– clearly not want.
and here’s thing: there no way around this; type templates distinct types (for reasons, too!) , cannot treat latter former – you have instantiate template type.
Comments
Post a Comment