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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -