Reputation: 584
Sometimes you still want the default move-constructor behavior (member-wise move), but also want to modify the moved-from object. Take the following scenario, for example
class Base{...}; // some move-constructible class
class Member{...}; // also move constructible
class Derived : public Base
{
public:
// does member-wise move, but nothing more
// Derived(Derived &&) = default;
// does member-wise move, same as default
// and also modifies `other`
Derived(Derived && other)
: a(std::move(other.a))
, b(std::move(other.b))
, ... // the rest of members
{
other.put_into_invalid_state_or_something();
}
//...............................................
// More functions
//...............................................
private:
// a lot of members...
Member a,b,c,d,e,f,g,h,i;
};
This may be a silly question, but is there any way to avoid writing the move for each member?
Upvotes: 0
Views: 122