Topic: Who is right on this C++ template example:
Author: sven-e@lysator.liu.se (Sven Rosvall)
Date: Sun, 30 Nov 2003 01:35:36 +0000 (UTC) Raw View
Hi,
I got a piece of code that works with G++ but not with Intels C++
compiler (based on EDG). I have also tried it on Comeau's web site
where you can try the latest version.
template <typename T, T * Data, int Size>
class BoundedExternalArray
{};
template <class Array>
class BoundedPointerTraits
{};
template <typename T, T * Data, int Size>
class BoundedPointerTraits<BoundedExternalArray<T, Data, Size> >
{};
The error message is on "Data" in the parameter list of the partial
specialisation. The message is 'the type of partial specialization
template parameter constant "Data" depends on another template
parameter'. Looking in the standard, I find 14.5.4/9, bullet 2: "The
type of a template parameter corresponding to a specialized non-type
argument shall not be dependent on a parameter of the specialization."
I cannot really relate to this. "T" is not being specialised here,
"Array" is. Am I reading in the right place?
A collegue had a look at this and came up with another example:
template <typename T, T * t, typename S>
class A;
template <typename T, T * t>
class A<T, t, int> {};
Same result, GCC accepts this code and EDG does not (both Intel and
Comeau). In this case it is clear that "T" is not specialised.
Only "S" is specialised here.
So, please help me understand the standard. Are any of these two
examples legal? Or both?
Thanks for any help.
/ Sven--
---
[ 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: richards_corden@hotmail.com (Richard Corden)
Date: Tue, 2 Dec 2003 18:44:18 +0000 (UTC) Raw View
Hi,
sven-e@lysator.liu.se (Sven Rosvall) writes:
<snip>
> template <typename T, T * t, typename S>
> class A;
>
> template <typename T, T * t>
> class A<T, t, int> {};
For me, 14.5.4/9 is dependent on t being specialized. And if t is
considered specialized in the above example then I think that the
example should be illegal.
However, 14.5.4/8 says that "A non-type argument is non-specialized if
it is the name of a non-type parameter. All other non-type argu-ments
are specialized."
So, I think the above is legal and that G++ is right.
Cheers,
Richard
--
Richard Corden
To reply remove 's' from address
---
[ 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 ]