c++ - how to specialize the template -


consider existing situation

template<typename t, int n = 10> struct {     //whatever };  template <typename t1,typename t2, typename t3> struct b;  template<typename t2, typename t3> struct b<double,t2,t3> {     //...  protected:    a<t2> mya; }; 

now i'm interesting able pass different default n a in specialization of b without changing declaration of b. possible?

i can think

template<typename t2, typename t3, int n> struct b<double,t2,t3> {     //...  protected:     a<t2,n> mya; }; 

but i'm not sure how use it...

well, class b usable that:

b<double, c, d> b; 

where cand d types themselves.

you cannot pass number there. specialization won't you. specialization don't change how can use class or parameters can pass, can change implementation set of parameter. said,

what suggest change declaration of b like:

template <typename, typename, typename, int = 10> struct b; 

ans specialization that:

template<typename t2, typename t3, int n> struct b<double,t2,t3, n> {     //...  protected:     a<t2, n> mya; }; 

so class both useable before, , this:

b<double, c, d, 11> b; 

if cannot change parameter are, can further specialize recieve type has number template parameter:

template<typename, int> struct typeandnumber {}; 

and change socialization that:

template<typename t2, typename t3, int n> struct b<typeandnumber<double, n>, t2, t3> {     //...  protected:     a<t2, n> mya; }; 

now class can useable that:

b<typeandnumber<double, 33>, c, b> b; 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -