Reputation: 2193
When people usually discuss or use move semantics, it's usually in the context of moving two classes of the same type.
Eg:
MyObject(MyObject &&obj) { // Implementation }
But what if MyObject is for the most part just wrapping an STL container like vector. Would making a move constructor that takes the vector and moves it considered an abuse of the functionality?
MyObject(vector<backingtype> &&v) : i_Backing(move(v)) {}
I ask this because I'm making a UTF-8 aware json parser which makes heavy use of copying whereas moving the container would be sufficient and faster.
auto arrayParseRes = jsonArrayParse(input); // Array parse res
auto jsonArray = JsonArray(arrayParseRes.Parse_Value()); // Currently copying json values
Upvotes: 1
Views: 186
Reputation: 119069
No, there is nothing at all wrong with moving from an rvalue passed to your constructor into one of your class members. The constructors for std::pair
and std::tuple
also do this.
Upvotes: 5