Topic: Explicit Specialization of Template Member Functions


Author: afnevrau@student.math.uwaterloo.ca (Adam Frank Nevraumont)
Date: 2000/11/13
Raw View
Greetings,

  I've run into an interesting bit of non-conformant code, at least I think
it is non-conformant.

(*)
struct test {
  template<class T> void foo(T) {}
  template<> void foo<int>(int) {}
};

  gcc, CodeWarrior and Comeau all aggree that the explicit specialization
within the class declaration itself isn't allowed.  The equivilent

(**)
struct test {
  template<class T> void foo(T) {}
};

template<> void test::foo<int>(int) {}

  however seems to work.  Now, reading over temp.*, I can't figure out
why the first snippet of code (*) is illegal, and neither can I figure out
why the standard would make it illegal.

  This is part of my usual problem of writing code that both (A) compiles
under MSVC and (B) is standards-compliant.  Unfortunetally, my attempts
to get the probably-standards-compliant snippet (**) to compile under MSVC
is running into problems.

  So, is (*) non-compliant?  Why?  Should it be?

  I'm guessing {"yes", "oops", "it shouldn't be"}, but I definately don't
understand the standard enough to be at all certain.


--
Adam_Nevraumont at uwaterloo.ca      The problem with the Big Blue Room is
'Nemo enim fere saltat sobris,       the daily 8 hour reboots.
 nisi forte insait.' -- Cicero       Quadrillionth binary digit of pi: 0
Hi.  Im the signature immune system.  Why dont you copy me into your .sig?

---
[ 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.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: wmm@fastdial.net
Date: 2000/11/14
Raw View
In article <8upobi$hok$1@watserv3.uwaterloo.ca>,
  afnevrau@student.math.uwaterloo.ca (Adam Frank Nevraumont) wrote:
>   I've run into an interesting bit of non-conformant code, at least I
think
> it is non-conformant.
>
> (*)
> struct test {
>   template<class T> void foo(T) {}
>   template<> void foo<int>(int) {}
> };
>
>   gcc, CodeWarrior and Comeau all aggree that the explicit
specialization
> within the class declaration itself isn't allowed.  The equivilent
>
> (**)
> struct test {
>   template<class T> void foo(T) {}
> };
>
> template<> void test::foo<int>(int) {}
>
>   however seems to work.  Now, reading over temp.*, I can't figure out
> why the first snippet of code (*) is illegal, and neither can I
figure out
> why the standard would make it illegal.
>
>   This is part of my usual problem of writing code that both (A)
compiles
> under MSVC and (B) is standards-compliant.  Unfortunetally, my
attempts
> to get the probably-standards-compliant snippet (**) to compile under
MSVC
> is running into problems.
>
>   So, is (*) non-compliant?  Why?  Should it be?
>
>   I'm guessing {"yes", "oops", "it shouldn't be"}, but I definately
don't
> understand the standard enough to be at all certain.

This question is discussed in the Core Language issues list,
http://www.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#44.
The resolution there is that explicit specializations must be
in namespace scope, not class scope, although there is some
possibility of relaxing that requirement at some point in the
future.  (The resolution was reaffirmed during discussions at
the Committee meeting last month and the issue's status was
changed to "ready.")

--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ 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.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]