1
class Foo { int a; int b; int c; std::wstring d; std::vector<char*> e };

Assuming a large string (~512 bytes) and ~512 bytes for the std::vector and it's use case as the following:

void Test()
{
    Foo foo;
    DoSomething(std::move(foo)); // DoSomething will stuff it in a long-lived queue
}

Essentially I want the RAII's object's lifetime to change.

Is this when I implement a move constructor and assignment operator? Or just doing std::move(..) is good enough?

2
  • Your vector is not actually holding strings, at most pointers to strings. Copying the Foo/the vector won't copy the strings in any case. Commented Oct 5, 2016 at 5:53
  • As soon as you start playing with pointers, assume the Rules of Three and Five are in effect Commented Oct 5, 2016 at 6:40

1 Answer 1

4

std::move is useless without move constructor and/or move assignment operator.

However all members of your class are movable and you don't have any user-defined destructor, copy constructor or copy assigment operator, so there will be an implicitly defined move constructor and move assignment operator doing the correct thing.

So in this specific case the answer is that you don't need to define a move constructor or assignment operator.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.