J
Johannes Schaub (litb)
Blanchet said: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.
Also, there is a destinction between "non-template" and "non-template
function":
- non-template: Anything that is not a template.
- non-template function: Anything that is a function, but is not a function
template specialization.
The first is a natural term which just says "not a template". I can't find
any other non-natural usage of it in the IS. But the latter has special
meaning in the IS: And it's used as if it's the negation of the pre-C++03
"template function" term, and as such excludes function template
specializations as opposed to "non-template".
12.8/p2 says "non-template constructor" so it means:
- Any constructor that is not a template
This includes constructors instantiated from templates, as opposed to
excluding them.