c++ template specialization and number of template arguments -
i have started learning templates, going through example typelist implemented , saw implementation of length method typelist.
template <class tlist> struct length; template <> struct length<nulltype> { enum { value = 0 }; }; template <class t, class u> struct length< typelist<t, u> > { enum { value = 1 + length<u>::value }; };
my question primary length template has 1 parameter (tlist) specialization has 2 parameters. how possible, read in other places specialization have less number of parameters
the first :
template <> struct length<nulltype>
is full specialization, second:
template <class t, class u> struct length< typelist<t, u> >
is partial specialization.
with full specialization give exact type on specialize. partial specialization allow types adheres restrictions, in case ability create type : typelist<t, u>
, 2 template type arguments must provided.
for more details see here:
http://en.cppreference.com/w/cpp/language/template_specialization http://en.cppreference.com/w/cpp/language/partial_specialization
my question primary length template has 1 parameter (tlist) specialization has 2 parameters. how possible,
thats partial specialization allow, template parameter list must differ (for details see above link), must provide same number of type arguments primary template expects (length< typelist<t, u> >
).
Comments
Post a Comment