Boost logo

Boost :

From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2001-07-11 05:17:02


Jason Shirk wrote:
> Your second example gives an error with VC7 Beta2. If you get rid of
> the explicit specialization, then it compiles without error and
> generates correct code. I'm not sure if the error is a bug or not. I
> have several compilers that can't agree on explicit specializations
> defined inside a class.

In-class specializations of member templates are not allowed (see
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#44 for the
details), so your compiler is correct here.

BTW, even if they were allowed, specializing a template assignment operator

template<typename U> A<T>& operator = (const A<U>& that);

for the case when U == T wouldn't make sense anyway, because such
specialization would never be called.

In fact, if you try to specialize it (in namespace scope) for a particular U
== T == int (for example; you can't specialize it for all U == T, even in
namespace scope), Comeau 4.2.45.2 issues the following diagnostic:

template<>
template<> A<int>&
A<int>::operator=(const A<int>& that) {
  return *this;
}

[Comeau C/C++ 4.2.45.2 for MS_WINDOWS_x86]
"E:\\depot\\libs\\msvc70.cpp", line 16: error #792:
          "A<int> &A<T>::operator=(const A<int> &) [with T=int]" is not an
          entity that can be explicitly specialized
  A<int>::operator=(const A<int>& that) {

Interesting, isn't it :)..

Aleksey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk