to enable move semantics on a C++ stl vector
You have misunderstanding about the move semantic concept.
The std::vector
itself is move constructable as it has the move constructor defined. You do not need to enable it explicitly, rather use it properly.
In the function
void setMyData(vector<string> sourceData) // copy 1
{
private_data_= sourceData; // copy 2
}
You are doing double copy. You need instead
void setMyData(vector<string> sourceData) // copy
{
private_data_= std::move(sourceData); // move
}
or you might want
void setMyData(vector<string>&& sourceData) // only accept the rvalue
{
private_data_= std::move(sourceData); // move
}
and for the second case, you call the function
setMyData(std::move(sourceData));