c++ - Template specialization for types providing a traits class -
i have class
template <typename t> struct dispatch;
which used call type-specific function. instance, assume have dispatchers like
template <> struct dispatch <myclass> { static void apply (void* a, myclass& m) { ::memcpy (a, &m, sizeof (m)); } };
now have bunch of classes have type-trait, arraytypes
. like:
template <> struct dispatch <enable_if<isarraytype>> { template <typename arraytype> static void apply (void* a, arraytype& m) { ::memcpy (a, &m, arraytypetraits<arraytype>::getsize (m)); } };
is possible?
use boost enable_if.
if boost unavailable, check out enable_if idiom.
Comments
Post a Comment