non-class template params in partial specializations

S

Samee Zahur

Why aren't we allowed to do partial specializations like these on
numeric template parameters? That would have allowed us to do all
kinds of interesting stuffs like loops of variable nesting (bad
practice though - I Know) and lots of other things!g++ even knows
that it is a partial specialization I am aiming for ... but it
just won't allow it!

//-----------------------------------------------------------------
template <unsigned X,unsigned Y> unsigned pow(){return pow<X,Y-1>();}
template <unsigned X> unsigned pow<X,0>(){return 1;} //ERROR!!

const unsigned var2=pow<2,5>();
//-----------------------------------------------------------------

Even funnier, complete specializations of these type are very legal!
For example,
//-----------------------------------------------------------------
template <unsigned X> unsigned powof3(){return 3*powof3<X-1>();}
template <> unsigned powof3<0>(){return 1;}

const unsigned var=powof3<4>();
//-----------------------------------------------------------------
and no one complains! but why is there a difference here?

Samee
 
V

Victor Bazarov

Samee said:
Why aren't we allowed to do partial specializations like these on
numeric template parameters? [...]

There are no partial specialisations of function templates. Period.
If you want to know the rationale behind it, post to comp.std.c++.
Here we discuss the "how", there they discuss the "why".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top