
template template parameter with default value (VS.NET 2003)
Quote:
> > Hi,
> > I'm trying to compile the following code, but there seems to be something
> > wrong either in my code or in the compiler (VS.NET 2003 beta)
> > Can anybody help me?
> There's an error in your code, and, I believe, a bug in the compiler.
> > Thanks
> > Wouter
> > #include "stdio.h"
> > template<int T = 10>
> > class AA
> > {
> > public:
> > void print() { printf("Value for template parameter = %d\n", T); }
> > };
> > template <template <int T1 = 34 > class T = AA< > >
> should be: template <template <int T1 = 34 > class T = AA >
> AA<> is not a template - it's a class, so you need to just use AA.
> > class BB
> > {
> > public:
> > T<> m_a;
> VC7.1 now complains about this line - too few actual parameters. It's
> apparently lost the existense of the default parameter for the default
> parameter. I can't quote chapter & verse that says this should compile, but
> Comeau compiles is, and it seems like it ought to be legal, doesn't it?
For me it looks absolutely illegal, allthough the C++ Standard Core
Language Issue Index then tells me that it's legal, so AFAICS you
are right.
Quote:
> Another question, of course, is which default value should be used (34 or
> 10)? :)
34
proof1: both 10 and 34 are '2*prime', but 17>5.
proof2: ISO+IEC+14882-1998.pdf (I hope so ;-)
proof3: cwg_closed.html#150
[...] Rationale: [...]
Default arguments are allowed for the parameters of a template
template parameter, and those default arguments alone will be
considered in a specialization of the template template parameter
within a template definition; any default arguments for the
parameters of a template template argument are ignored.
'template definition' = BB's definition
'template template parameter' = T
'specialization of the template template parameter' = "T<> m_a;"
'template template argument' = AA (for decl. "BB< > test;")
So last sentence becomes "any def args for AA's parameters
are ignored".
proof4: cwg_active.html#184
This is about how to handle a more complicated case where
it seems stdc++ is unclear, and then results like ...
---------------------------------------
template <template <int T1 = 34> class T = AA>
class CC
{
public:
T<> m_a ;//-> T<34>
void print();
void f();
Quote:
};
template <template <int T1 = 62> class T = AA>
void CC<T>::print()
{
m_a.print() ;//T<34>.print
T<> a; a.print();//T<62>.print
Quote:
}
template <template <int T1> class T = AA>
void CC<T>::f()
{
T<> a; a.print();//error - T1 has no default template argument
Quote:
}
---------------------------------------
Regards,
Markus.