template template parameter with default value (VS.NET 2003) 
Author Message
 template template parameter with default value (VS.NET 2003)

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?

Thanks

Wouter

#include "stdio.h"

template<int T = 10>
class AA
{
        public:
                void print() { printf("Value for template parameter = %d\n", T); }

Quote:
};

template <template <int T1 = 34 > class T = AA< > >
class BB
{
        public:
                T<> m_a;

                void print() { m_a.print(); }

Quote:
};

int main()
{
        BB< > test;
        test.print();
Quote:
}



Sat, 14 May 2005 18:27:39 GMT  
 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.

Quote:

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

Quote:
> 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?

Another question, of course, is which default value should be used (34 or
10)?  :)

- Show quoted text -

Quote:

> void print() { m_a.print(); }
> };

> int main()
> {
> BB< > test;
> test.print();
> }



Sat, 14 May 2005 22:26:22 GMT  
 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.



Sun, 15 May 2005 01:15:10 GMT  
 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.

Issue 184 has "ready" status, so it is not yet an approved defect.  Issue
150 (in part it's the same) has "extension" status.

So this is not yet a compiler bug, although it seems entirely reasonable
that we handle this as EDG does.  I'll make sure we keep this issue in mind
for the next release.
--
Jason Shirk

Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no
rights.



Sun, 15 May 2005 03:31:16 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. template-template params default values - std::deque

2. WORKAROUND: nested template type default parameter values

3. Resolving overload Template operator<<() with VS 2003

4. friend template in .NET 2003

5. Visual C++ .net 2003 template error

6. Visual C++ .net 2003 template error

7. VC7 does NOT support template-template parameters involving non-type parameters

8. Visual C++.NET 2003 will have template template parameters?

9. VS.NET 2003 VC++ and .NET controls

10. Debugging with VS.NET 2003 and VS 6

11. VC 7.1 final beta: bug with template template parameters

12. Template argument dependant default parameter

 

 
Powered by phpBB® Forum Software