Here's the definition of copy constructor, [class.copy.ctor/1]:
A non-template constructor for class X is a copy constructor if its first parameter is of type X&, const X&, volatile X& or const volatile X&, and either there are no other parameters or else all other parameters have default arguments ([dcl.fct.default]).
Why does the standard exclude templates as copy constructors?
In this simple example, both constructors are copy constructors:
struct Foo {
Foo(const Foo &); // copy constructor
Foo(Foo &); // copy constructor
};
See this similar example:
struct Foo {
Foo() = default;
template <typename T>
Foo(T &) {
printf("here\n");
}
};
int main() {
Foo a;
Foo b = a;
}
In this example, here
will be printed. So it seems that my template constructor is a copy constructor, at least it behaves like one (it is called in a context where copy constructors are usually called).
Why is the "non-template" requirement there in the text?
Foo b = a
instantiates and callsFoo::Foo<Foo>(Foo&)
. It might rather call the implicitly declared copy constructor. – Archfiend[class.copy.ctor]/1 & /6
. – ArchfiendFoo c = std::move(a);
? – Absinthetemplate <typename T> Foo(T&)
isn't handled anywhere. Am I missing something? – Pavlov