C++ gurus - really dumb question regarding partial speciallization.

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
struct safe_range1

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. -- Jeremiah Willcock

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

Vicente J. Botet Escriba wrote:
// 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.
Actually, I figured this out. Thanks for everyone's help. I was really mixed up about which list of arguments are the ones which get matched. That is - the ones in the template<....> vs the list of ones in the struct x<....>. I realise that that things are the way they are for a reason, but still C++ has a number of syntax issues which makes it hard to keep in my head. Robert Ramey
participants (3)
-
Jeremiah Willcock
-
Robert Ramey
-
Vicente J. Botet Escriba