5

What happens if std::move() is called on a user defined object, that defines no move constructor? Is it simply copied?

3
  • 1
    You mean with a deleted move constructor? Because if you don't define a move constructor yourself, and all of the objects members have a move constructor, a trivial move constructor is generated. Commented Dec 10, 2013 at 22:04
  • 3
    Note that std::move by itself does nothing to an object. So the answer depends on the context. For example, the moved from object could be used for a move assignment. Or something entirely different. So it is not totally dependent on the type being move constructible Commented Dec 10, 2013 at 22:04
  • 1
    std::move does not move, and std::forward does not forward. Commented Dec 10, 2013 at 22:08

1 Answer 1

5

Yes, move will fall back to copy. This is how standard containers like std::vector can implement resizing in terms of move, but remain compatible with classes which can only be copied.

However, the class may have an implicitly defined move constructor - see this guidance. http://en.cppreference.com/w/cpp/language/move_constructor#Implicitly-declared_move_constructor

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.