std::move doesn't move anything: A deep dive into Value Categories
0xghost.dev·4w·
Discuss: r/programming
🔒Type Safety
Preview
Report Post

12/9/2025 42 min

The Problem: When “Optimization” Makes Things Slower

Let’s start with something that trips up even experienced developers. You write what looks like perfectly reasonable C++ code:

struct HeavyObject {
std::string data;

HeavyObject(HeavyObject&& other) : data(std::move(other.data)) {}

HeavyObject(const HeavyObject& other) : data(other.data) {}

HeavyObject(const char* s) : data(s) {}
};

std::vector<HeavyObject> createData() {
std::vector<HeavyObject> data;
// ... populate data ...
return data;
}

void processData() {
auto result = createData();
}

This code works. It compiles. It runs. But depending on how you’ve implemented your types, it might be performing thousands of expensive copy operations instead of cheap moves without you realizing it. …

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help