c++ - Knowing the number of template parameters in the declaration -
c++ - Knowing the number of template parameters in the declaration -
if have,
template<typename t1, typename t2, int n> class x {};
is there way, can know class x
has 3 template
arguments ?
use case in brief: there 2 library classes ptr<t>
(for normal pointer) , ptr_arr<t,n>
(for pointer array). these 2 interacting class in next way:
template<typename t> void clear(const t &obj) { if(t::args == 1) destroy(obj); else destroy_arr(obj); }
so, thought if have handy way of knowing number of parameters, create easy. however, larn need alter business logic there cannot such way.
there no standard way (unless utilize variadic sizeof(args...)
in c++0x) that's beside point -- question wrong.
use overload resolution.
template <typename t> void clear (ptr<t> & obj) { destroy (obj); } template <typename t, int n> void clear (ptr_arr<t,n> & obj) { destroy_arr (obj); }
c++ templates
Comments
Post a Comment