Move Semantics

We will talk about properties of the move semantic in this lesson that are not mentioned as often.

Containers of the STL can have non-movable elements. The copy semantic is the fallback for the move semantic.

Let’s learn more about the move semantic.

std::move

The function std::move moves its resource.

  • Needs the header <utility>.
  • Converts the type of its argument into a rvalue reference.
  • The compiler applies the move semantic to the rvalue reference.
  • Is a static_cast to a rvalue reference under the hood.
static_cast<std::remove_reference<decltype(arg)>::type&&>(arg);
  • What is happening here?
...