C/C++ Arena

Step 5 of 7

Moved-from objects

After b = std::move(a);, what is a? For standard library types the rule is valid but unspecified:

So the professional habit is: after moving from something, either stop using it or reset it explicitly.

std::vector<std::string> batch = std::move(pending);
pending.clear();   // now it's definitely empty and ready to reuse

Your turn: write std::vector<std::string> take_all(std::vector<std::string>& src) that moves the whole contents out of src (no element copies) and leaves src definitely empty.

Previous: Return by value is free Next: Sink parameters and emplace_back