Blanchet Florian wrote:
In article <i8pkvg$20r$03$1@news.t-online.com>, Johannes Schaub (litb)
says...
It says that a constructor of class X whose first parameter is of type
"cv X&" and either there are no other parameters or all other parameters
have default arguments, is a copy constructor. This does not apply to
the above template, and so it is *not* a copy constructor.
I'm agree with James. It's not a copy constructor because the draft says
"A non-template constructor for class X is a copy constructor if ..."
and not only "its first parameter is of type X&,...".
If it was just "its first parameter is of type X&,...", the result of
struct A { template<class T> A(T&){std::cout << 0} };
int main() { A a; A b(a); return 0; }
would be "0", because the template constructor A<A>(A&) is a constructor
and is first parameter is of type A&. And the result isn't "0".
I keep disagreeing This is allegedly forbidden (by the interpretation of
some people) by another paragraph, namely 12.8/p3 "A member function
template is never instantiated to perform the copy of a class object to an
object of its class type." (See the other post of me where I link to an
issue report about the interpretation of this).
12.8/p2 has nothing to do with it. The stuff you quote from p2 says that a
*non-template* can be a copy constructor - in other words a template
cannot be a copy constructor. A function instantiated from a template is
not a template. So it does entirely not apply, see below.
In addition, nothing says that only copy constructors are allowed to copy
an object. So even if it were like you are saying and "A non-template ..."
makes also the specialization non-copy constructors, that wouldn't change
anything with regard to your example above.
What it makes sure is that the following template declaration does not
inhibit the implicit declaration of a copy constructor
struct A {
template<typename T = int>
A(A const&);
};
If we take out "A non-template" then in C++0x the above will not have an
implicitly declared copy-constructor anymore, because the template will be
a copy constructor. Now I was stating such code is impossible in C++03
anyway because in C++03 you must arrange for "T" to be deduced from the
arguments, and then you cannot satisfy the conditions for copy
constructors anymoe.
discussion. The following *is* valid C++03:
So please take this into account when answering. I was overlooking this and