Move Semantic
We will talk about some important, often overlooked properties of the move semantic in this lesson.
We'll cover the following...
Containers of the standard template library (STL) can have non-copyable 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.
- The function needs the header
<utility>
. - The function converts the type of its argument into a rvalue reference.
- The compiler applies move semantic to the rvalue reference.
std::move
is under the hood astatic_cast
to an rvalue reference.
static_cast<std::remove_reference<decltype(arg)>::type&&>(arg);
- What is happening here?
decltype(arg)
: deduces the type of the argumentstd::remove_reference<....>
removes all references from the type of the argumentstatic_cast<....&&>
adds two references to the type
...