C++ std::move doesn’t move anything: A deep dive into Value Categories

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….

Read more on Hacker News