Topic: When are non-type parameters specialized?


Author: japple@freeshell.org (Gina Yarmel)
Date: Tue, 23 Dec 2003 02:05:57 +0000 (UTC)
Raw View
(Graeme Prentice) wrote:

> The C++ standard is a little confusing in 14.5.4/9 where it gives this
> as an example of a "partially specialised non-type argument expression"
>
> template <int I, int J> struct B {};
> template <int I> struct B<I, I> {}; // OK
>
> The specialization above meets the requirement in para 9  (quote)  "The
> argument list of the specialization shall not be identical to the
> implicit argument list of the primary template."  - yet the standard
> gives no definition of what a partially specialised non-type argument
> expression is, and in the example just above, the two arguments (<I,I>)
> are both the name of a non-type parameter, so are therefore
> non-specialized  - so how can the second arg. be "partially
> specialised".

I agree.  14.5.4/9 should read something like,
"A non-type argument is non-specialized if it is the name of its
corresponding parameter in the specialized parameter list.  If there
is no corresponding parameter, the argument is specialized. All other
non-type arguments are specialized."

> The second bullet of para 9 is also a little unclear where it says
> <quote>
> The type of a template parameter corresponding to a specialized nontype
> argument shall not be dependent on a parameter of the specialization.
> <>
> then gives this example
>
> template< int X, int (*array_ptr)[X] > class A {};
> int array[5];
> template< int X > class A<X,&array> { }; // error
>
> Presumably array_ptr is the template parameter that corresponds to the
> specialized non-type argument &array ??  - but what is its type?  Lets
> say its type is
> int (*)[5]
> how is this type dependent on the X parameter in the specialization?

X must be 5. I don't think I understand the question.

Jim

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: invalid@yahoo.co.nz (Graeme Prentice)
Date: Tue, 23 Dec 2003 17:05:39 +0000 (UTC)
Raw View
On Tue, 23 Dec 2003 02:05:57 +0000 (UTC), Gina Yarmel wrote:

>(Graeme Prentice) wrote:
>
>> The C++ standard is a little confusing in 14.5.4/9 where it gives this
>> as an example of a "partially specialised non-type argument expression"
>>
>> template <int I, int J> struct B {};
>> template <int I> struct B<I, I> {}; // OK
>>
>> The specialization above meets the requirement in para 9  (quote)  "The
>> argument list of the specialization shall not be identical to the
>> implicit argument list of the primary template."  - yet the standard
>> gives no definition of what a partially specialised non-type argument
>> expression is, and in the example just above, the two arguments (<I,I>)
>> are both the name of a non-type parameter, so are therefore
>> non-specialized  - so how can the second arg. be "partially
>> specialised".
>
>I agree.  14.5.4/9 should read something like,
>"A non-type argument is non-specialized if it is the name of its
>corresponding parameter in the specialized parameter list.  If there
>is no corresponding parameter, the argument is specialized. All other
>non-type arguments are specialized."

I was saying that the description of the argument expression as
"partially specialized" conflicts with the definition of what a
specialized argument is.  As John Spicer has pointed out, the argument
list in the specialization corresponds to the template parameter list in
the primary template  - they must match in number, kind and type.  There
is no "correspondence" between the template parameter list of the
partial specialization and the argument list, so it's not possible to
say that an argument has a "corresponding parameter" in the specialized
parameter list.

IMO an argument should be considered specialised when it is a narrower
range of type or value than the primary template.


>
>> The second bullet of para 9 is also a little unclear where it says
>> <quote>
>> The type of a template parameter corresponding to a specialized nontype
>> argument shall not be dependent on a parameter of the specialization.
>> <>
>> then gives this example
>>
>> template< int X, int (*array_ptr)[X] > class A {};
>> int array[5];
>> template< int X > class A<X,&array> { }; // error
>>
>> Presumably array_ptr is the template parameter that corresponds to the
>> specialized non-type argument &array ??  - but what is its type?  Lets
>> say its type is
>> int (*)[5]
>> how is this type dependent on the X parameter in the specialization?
>
>X must be 5. I don't think I understand the question.

I think it's a confusing example because you could argue that the type
of array_ptr is determined by the second argument and is therefore
independent of X for the given specialization, even though only one
value of X satisfies.  I think I was trying to say that the template
parameters in the specialization don't have a direct relationship with
the parameters in the primary template, so establishing "dependency"
means involving the argument list  -  exactly what is meant by
dependency doesn't seem very clear to me and the error message reported
by the Comeau compiler indicates a different interpretation of the
second bullet of para 9.

I tried to produce another example but GCC won't compile this code and
my version of the Comeau compiler crashes with it.

template< int X, int Y, int (*array_ptr)[Y] > class A {};
int array[5];

template< int X > class A<X,5,&array> { };

int main()
{
    A<6,5,&array> x1;
}

Graeme

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: taintedwheat@yahoo.com (Gina Yarmel)
Date: Sat, 20 Dec 2003 07:14:09 +0000 (UTC)
Raw View
The following:

template<typename T, T N, int X>
struct base {};

template<typename T, T N>
struct base<T,N,0> {};

fails to compile on Comeau online with the following error message:

the type of partial specialization template parameter constant "N"
depends on another template parameter
template<typename T, T N>
                       ^

But, 14.5.4/9, bullet 2 says,
"The type of a template parameter corresponding to a specialized
non-type argument shall not be dependent on a parameter of the
specialization."
and 14.5.4/8 says,
"A non-type argument is non-specialized if it is the name of a
non-type parameter."

This looks to me like N is not specialized, but 0 is.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: invalid@yahoo.co.nz (Graeme Prentice)
Date: Sun, 21 Dec 2003 20:25:52 +0000 (UTC)
Raw View
On Sat, 20 Dec 2003 07:14:09 +0000 (UTC), Gina Yarmel wrote:

[snip]

>and 14.5.4/8 says,
>"A non-type argument is non-specialized if it is the name of a
>non-type parameter."
>
>This looks to me like N is not specialized, but 0 is.

I think you are right - N is not specialized.  VC7.1 and GCC compile
your code without error.  This looks like a bug/error in the Comeau
compiler.  You should email the Comeau or EDG people about this.

The C++ standard is a little confusing in 14.5.4/9 where it gives this
as an example of a "partially specialised non-type argument expression"

template <int I, int J> struct B {};
template <int I> struct B<I, I> {}; // OK

The specialization above meets the requirement in para 9  (quote)  "The
argument list of the specialization shall not be identical to the
implicit argument list of the primary template."  - yet the standard
gives no definition of what a partially specialised non-type argument
expression is, and in the example just above, the two arguments (<I,I>)
are both the name of a non-type parameter, so are therefore
non-specialized  - so how can the second arg. be "partially
specialised".

The second bullet of para 9 is also a little unclear where it says
<quote>
The type of a template parameter corresponding to a specialized nontype
argument shall not be dependent on a parameter of the specialization.
<>
then gives this example

template< int X, int (*array_ptr)[X] > class A {};
int array[5];
template< int X > class A<X,&array> { }; // error

Presumably array_ptr is the template parameter that corresponds to the
specialized non-type argument &array ??  - but what is its type?  Lets
say its type is
int (*)[5]
how is this type dependent on the X parameter in the specialization?

Do I misunderstand?

Graeme

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]