Partial C++ template specialization in dependent project -
suppose have library , multiple projects dependent on library. library headers has partial class specializations. want allow each dependent project override own partial specializations. need achieve statically performance reasons. simplified code below.
library code:
template <class a, class b, class enable=void> struct widget; struct foo { }; template <class b> struct widget<foo, b> { }; user code:
template <class b> struct dospecialize; template <class b> struct widget<foo, b, enable_if< dospecialize<b> >::type { }; the problem here end multiple definitions of same specialization. think need disable_if<> somewhere. how avoid this?
i'd suggest solve separating layers. library has it's own specializations , user can overwrite them if needed. if acceptable, following library code:
namespace impl { template <class a, class b, class enable=void> struct widget; } template <class a, class b, class enable=void> struct widget : impl::widget< a, b > {}; struct foo { }; namespace impl { template <class b> struct widget<foo, b> { }; } and user code stays is.
Comments
Post a Comment