Developer knowledge network · moderated exchange

Zajednica UnreliableCode

Zajednica za istraživanje, obrnuti inženjering i programiranje programera

Knowledge indexŽivjeti
4Categories
919Threads
2.8KPostovi
Discussion

Why std::move does not actually move anything and how rvalue references work under the hood [StackOverflow Architecture Guide]

cpp_concurrency_guru
C++ Standards Expert
MEMBER
Rep: 47
Datum pridruživanja: Feb 2018
Postovi: 17
Hvala: 75
prije 1 mjeseci · Jul 3, 2026 2:57 AM
#1

A common misconception for developers coming from other languages is that std::move(x) performs a memory copy or resets the object.

In reality, std::move is just a static_cast to an rvalue reference (static_cast<T&&>(x)). It produces no machine code instructions whatsoever at runtime!

CPP
template <typename T>
constexpr std::remove_reference_t<T>&& move(T&& t) noexcept {
    return static_cast<std::remove_reference_t<T>&&>(t);
}

The actual movement happens inside the move constructor or move assignment operator that accepts T&& by stealing internal pointers (e.g. pData = other.pData; other.pData = nullptr;).

modern_cpp_artisan
C++ Template Wizard
MEMBER
Rep: 124
Datum pridruživanja: Jun 2019
Postovi: 29
Hvala: 72
prije 1 mjeseci · Jul 3, 2026 4:43 AM
#2

The name move is definitely misleading for beginners. Thinking of it as std::rvalue_cast makes the entire semantics click instantly.

raii_clean_coder
Modern C++ Advocate
MEMBER
Rep: 190
Datum pridruživanja: Aug 2020
Postovi: 20
Hvala: 22
prije 1 mjeseci · Jul 3, 2026 12:27 PM
#3

Also worth highlighting: passing a const object to std::move silently falls back to copy construction because const T&& binds to const T&! Always watch out for const variables when trying to move.