Template-template parameter involving a non-type parameter

Template-template parameter involving a non-type parameter

Post by Shannon Barb » Sat, 30 Nov 2002 08:23:16



I just wanted to check that the following is in fact standard code.
Does anyone see any faults with it?  It compiles with gcc 3.2 and the
online Comeau compiler (ignoring warnings about the variables never
used).

It's just an example to test a template-template parameter of a
template employing a non-type parameter - something that MSVC7
apparently does not support.  Would it be rash to conclude that MSVC7
thus does not fully support template-template parameters since it
fails to compile the example code below?

gcc: Compilation Successful
Comeau: Compile succeeded
MSVC7: error C3201: the template parameter list for class template
'Count' does not match the template parameter list for template
parameter 'TemplateTemplate'

[source]
template<int First_Tag>
struct Count
{
enum Tags
     {
     First = First_Tag,
     Last
     };

Quote:};

template<template<int> class TemplateTemplate>
struct BPoS
{
enum {value = TemplateTemplate<5>::Last};

Quote:};

int main()
{
BPoS<Count> bpos;
Quote:}

[/source]


      [ about comp.lang.c++.moderated. First time posters: do this! ]

 
 
 

Template-template parameter involving a non-type parameter

Post by Carl Danie » Mon, 02 Dec 2002 06:40:28



Quote:> I just wanted to check that the following is in fact standard code.
> Does anyone see any faults with it?  It compiles with gcc 3.2 and the
> online Comeau compiler (ignoring warnings about the variables never
> used).

> It's just an example to test a template-template parameter of a
> template employing a non-type parameter - something that MSVC7
> apparently does not support.  Would it be rash to conclude that MSVC7
> thus does not fully support template-template parameters since it
> fails to compile the example code below?

Legal, so your conclusion about VC7 wouldn't be rash.

VC7.1 compiles it.

-cd


      [ about comp.lang.c++.moderated. First time posters: do this! ]

 
 
 

1. Templates & specialization: dependence of typed parameters on non-type ones.

The following code is clearly disallowed in the standard:

template<class T, T t> struct X {};
template<class T> struct X<T,1> {};

...since a non-type parameter can not force the type of a typed one.

However, it seems to me that the wording (can't remember the exact
paragraph) is ambiguous about the following:

template<class T, class U, U u> struct X {};
template<class T> struct X<T,int,1> {};

Is this legal or illegal code?  If illegal, is it illegal for a good
reason?

Side note: if you enter the 2nd example into
http://www.comeaucomputing.com/tryitout (along with an instantiation
of the specialization such as "X<char,int,1> x;"), the compile fails,
but gives no errors.  Internal error?

2. Earn Upwards of $10000 per month

3. non-type template-parameter types

4. Internet Theft Crackdown

5. access to non-type template parameters

6. Opening existing web

7. question about non-type template parameters

8. Dynamically created Event Handlers

9. weird error with non-type parameter function template specializations

10. Acceptable values for non-type template parameters?

11. Non-type parameters of template functions

12. Pointer to member as non-type template parameter

13. template non-type parameters