Le 19/12/12 20:31, Jeremiah Willcock a écrit :
On Wed, 19 Dec 2012, Robert Ramey wrote:
I've got the following code which fails to compile. I'm really stumped by this. I've consulted the standard document on the subject and for the life of me I can't see anything wrong with it. It fails with the same message on vc 9.0 as well as gcc 4.5.3. It's so simple it can't be a compiler issue.
I appoligize in advance for spaming the list here - but I'm really, really stuck.
Robert Ramey
// primary template template< class T, int MIN, int MAX
struct safe_range1{};
// instantiate primary as a test safe_range1
t1; // partial specialization # 1 template< int MIN, int MAX
struct safe_range1
{}; // instantiate partial specialization - what the ??? // fails with "too few template parameters" !!! safe_range1<0, 1> t2;
// partial specialization # 2 template<class T> struct safe_range1
{}; // also fails with "too few template parameters" !!! safe_range1<int> t3;
Your template, and all of the partial specializations, have three parameters and no defaults. Partial specialization #1 just states that when int is used as the first argument to safe_range1, it will use that case, but that doesn't change the parameter type.
You could get something close using template alias (c++11), but of course you need to have a different name. Vicente