When providing a function that copies a large object, do I need to provide an explicit override accepting an rvalue to benefit from move assignment?
Most of the discussion of when to explicitly provide rvalue overrides is focused on constructors and assignment operators, or return values. But I can't quite figure out how it applies to copying/move-assigning large objects.
consider:
struct A{
//my owned data, any large object that implements move assignment
std::vector<std::string> myvec;
//pre-c++11, this would assign by copy
void Set(const std::vector<std::string>& vec){ myvec = vec; }
//c++11, explicitly move assign
void Set(std::vector<std::string>&& vec){ myvec = std::move(vec); }
};
A a;
a.Set(std::vector<std::string>({"hello","world"});
If I call Set with an lvalue, the first version of the method (const T& will be called, and the assignment will be done by copy. As it is written, the call at the bottom of the snippet will call the second version of Set (T&&) because the temporary object is an rvalue.
I read somewhere (can't find the reference now) that const T& can bind to rvalues. If that's the case, and my T implements a move-assign operator (as std::vector does), will the first version allow efficient move-assignment of rvalues, making the T&& override unnecessary?