Reputation: 920
I have a templated container class:
template<class Stuff>
class Bag{
private:
std::vector<Stuff> mData;
};
I want to do
void InPlace(Bag<Array>& Left){
Bag<Array> temp;
Transform(Left, temp); //fills temp with desirable output
Left = std::move(temp);
}
Suppose Array has user-defined move semantics, but Bag does not. Would mData in this case be moved or copied?
Upvotes: 6
Views: 850
Reputation: 36503
It would be moved, not copied.
I would suggest looking at the following image:
This clearly shows that the compiler implicitly generates a move constructor as long as the user doesn't define his/her own :
Since your class has none of these user defined constructors the compiler generated move constructor will be called, that constructor will move mData
.
Upvotes: 9