Consider the following:
struct X
{
Y y_;
X(const Y & y) :y_(y) {}
X(Y && y) :y_(std::move(y)) {}
};
Is it necessary to define a constructor like the second one in order to take full advantage of move semantics? Or will it be taken care of automatically in the appropriate situations?
Yes, but no. Your code should just be this:
If you ever say in design “I need my own copy of this data”*, then you should just take the argument by value and move it to where it needs to be. It isn’t your job to decide how to construct that value, that’s up to the available constructors for that value, so let it make that choice, whatever it is, and work with the end result.
*This applies to functions too, of course, for example:
Note that is applied in C++03 too, somewhat, if a type was default constructible and swappable (which is all moving does anyway):
Though this didn’t seem to be as widely done.