c++ - Template specialization with compile time constant -
i trying build specialization template class compile time constant.
the template class looks this:
template<class tnativeitem, class tcomitem = void, vartype _vartype = _atl_automationtype<tcomitem>::type> class inoutcomarray { private: ccomsafearray<tcomitem, _vartype> _safearray; // ... public: inoutcomarray( tnativeitem* items, size_t length, std::function<tcomitem(const tnativeitem&)> converttocom, std::function<tnativeitem(const tcomitem&)> convertfromcom) : _safearray(length) { // ... } // ... };
usage example:
inoutcomarray<bool, variant_bool, vt_bool>( items, length, booltovariant_bool, variant_booltobool));
however, there exist types don't require conversion , wanted provide short hand version this:
inoutcomarray<long>(items, length);
i tried implement this:
template<class titem, vartype _vartype = _atl_automationtype<titem>::type> class inoutcomarray<titem, void, _vartype> : public inoutcomarray<titem, titem, _vartype> { public: inoutcomarray(titem* items, size_t length) : inoutcomarray<titem, titem, _vartype>( items, length, noconverter<titem>, noconverter<titem>) { } };
however, following error:
'_vartype' : default template arguments not allowed on partial specialization
is there way around that?
you first define default arguments void
, _atl_automationtype<tcomitem>::type
, when 1 argument x given, want inoutcomarray<x>
inoutcomarray<x, void, _atl_automationtype<void>::type>
.
your partial specialization contradicts this: inoutcomarray<x>
shall inoutcomarray<x, x, _atl_automationtype<x>::type>
.
depending on thik more second argument, (i.e. void
or same first argument), make second argument defaulted first 1 in first place:
template<class tnativeitem, class tcomitem = tnativeitem, vartype _vartype = _atl_automationtype<tcomitem>::type>
that way behavior of partial specialization covered, except additional constructor. can achieved using default arguments constructor:
template<class tnativeitem, class tcomitem = tnativeitem, vartype _vartype = _atl_automationtype<tcomitem>::type> class inoutcomarray { public: inoutcomarray( tnativeitem* items, size_t length, std::function<tcomitem(const tnativeitem&)> converttocom = noconverter<tnativeitem>(), std::function<tnativeitem(const tcomitem&)> convertfromcom = noconverter<tnativeitem>()); };
Comments
Post a Comment