Developer knowledge network · moderated exchange

Społeczność UnreliableCode

Badania programistów, inżynieria wsteczna i społeczność programistów

Knowledge indexNa żywo
4Categories
919Threads
2.8KPosty
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
Rozpustnik: 47
Data dołączenia: Feb 2018
Posty: 17
Dzięki: 75
1 miesięcy temu · 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
Rozpustnik: 124
Data dołączenia: Jun 2019
Posty: 29
Dzięki: 72
1 miesięcy temu · 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
Rozpustnik: 190
Data dołączenia: Aug 2020
Posty: 20
Dzięki: 22
1 miesięcy temu · 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.