Topic: specialization of member class templates
Author: Stefan Schwarzer <sts@boa.ica1.uni-stuttgart.de>
Date: 1999/05/12 Raw View
I am trying to figure out the rationale behind the rules for
specialization of class member templates:
struct A {
template<class T>
struct B {};
};
Now, for several reasons, I would like to specialize B:
struct A {
template<class T>
struct B {};
template<> // error: KCC, cxx, egcs 19990502
// explicit spec. not allowed
// ok: compiles with egcs-1.1.2, though
struct B<double>{};
};
The standard forbids specialization of class member templates if the
enclosing class is a non-specialized template (14.7.3.18).
First, here the enclosing class is not a template, so does 14.7.3.18 even
apply?
Second, if it were a template, I still would not see a problem, since,
e.g., even if B dissappeared from subsequent specializations of the
enclosing class, so would my specialization?
Also, if there is a compelling reason for the rule (14.7.3.18)
then why is the following _partial_ specialization legal (or at least
accepted by some compilers)?
struct A {
template<class T, class U>
struct B{
// dont use U
};
template<class U>
struct B<double,U>{ // ok: cxx, KCC, egcs 19990502
// error: egcs-1.1.2 (prev. decl. used 2 args)
// dont use U
};
};
I'd be grateful to be enlightened by an expert as to what the
standard really intents to say on this topic...
--
Stefan Schwarzer office: +49-(0)711-685-7606 fax: x-3658
Uni Stuttgart, ICA 1 e-mail: sts@ica1.uni-stuttgart.de
Pfaffenwaldring 27 pgp public key available on request/finger
70569 Stuttgart, Germany http://www.ica1.uni-stuttgart.de/~sts
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: sbnaran@localhost.localdomain (Siemel Naran)
Date: 1999/05/16 Raw View
On 12 May 99 16:59:49 GMT, Stefan Schwarzer
This question arose on comp.std.c++ before. But the resolution does not
seem clear to me.
>struct A {
> template<class T>
> struct B {};
> template<> // error: KCC, cxx, egcs 19990502
> // explicit spec. not allowed
> // ok: compiles with egcs-1.1.2, though
> struct B<double>{};
>};
This seems well-formed.
>The standard forbids specialization of class member templates if the
>enclosing class is a non-specialized template (14.7.3.18).
>First, here the enclosing class is not a template, so does 14.7.3.18 even
>apply?
It doesn't seem that 14.7.3.18 should apply here.
But another rule does apply: one can't reopen a class definition and
change what one doesn't like (unlike namespaces). This means that
specializations outside the class definition should not be allowed.
That's why the above code seems well formed.
>Second, if it were a template, I still would not see a problem, since,
>e.g., even if B dissappeared from subsequent specializations of the
>enclosing class, so would my specialization?
Specializations outside the class definition are not allowed because of
the reason given above.
Another reason. Specializations outside the class definition are not
allowed because you may be specializing something which does not exist!
Eg,
template <class T> struct A { template <class T> struct B { } }; // LINE1
template <class T> template <> struct A<T>::B<int> { int i; }; // LINE2
template <> struct A<int> { }; // LINE3
The following program
int main() { A<int>(); }
causes problems because LINE2 doesn't make sense.
>Also, if there is a compelling reason for the rule (14.7.3.18)
>then why is the following _partial_ specialization legal (or at least
>accepted by some compilers)?
>
>struct A {
> template<class T, class U>
> struct B{
> // dont use U
> };
> template<class U>
> struct B<double,U>{ // ok: cxx, KCC, egcs 19990502
> // error: egcs-1.1.2 (prev. decl. used 2 args)
> // dont use U
> };
>};
This looks like a bug.
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]