I would like to know how to write a move assignment operator in the following case:
class Foo : public vector<int>
{
public:
Foo(Foo&& other) : vector<int>(move(other)) {};
Foo& operator=(Foo&& other){ ????? };
};
How's it done?
Thanks, Tom
I would like to know how to write a move assignment operator in the following case:
class Foo : public vector<int>
{
public:
Foo(Foo&& other) : vector<int>(move(other)) {};
Foo& operator=(Foo&& other){ ????? };
};
How's it done?
Thanks, Tom
class Foo
: public vector<int>
{
public:
auto operator=( Foo&& other )
-> Foo&
{
vector<int>::operator=( move( other ) );
return *this;
};
Foo( Foo&& other )
: vector<int>( move( other ) )
{};
};
Or just
class Foo
: public vector<int>
{
public:
auto operator=( Foo&& other ) -> Foo& = default;
Foo( Foo&& other )
: vector<int>( move( other ) )
{};
};
I'm not sure of the rules for automatic generation of move assignment operator, and would currently not yet rely on the compiler implementing those rules correctly (as of June 2014).