Is this a correct move constructor?

Hi,

Say I have a struct Widget that supports moving operations:

struct Widget {
std::string name;
Widget( Widget&& w) : name { std::move( w.name) } {}
Widget& operator=( Widget&& w ) {
name = std::move( w.name );
return *this;
}
};

Is it correct to move the string in name? Is this the way to write a moving struct that has one string data member? Should I have used std::forward so the cast is done conditionally?

Thanks,
Juan
What you have written is correct. Note that in this simple case there was no need to define a move constructor and move assignment operator because the implicit defined ones would do the exact same thing.
Topic archived. No new replies allowed.