For move construction:
After the move, other is guaranteed to be empty(). 1
For move assignment, the oft-quoted:
other is in a valid but unspecified state afterwards. 2
Why is the state of other different in these two cases?
There are 2 popular ways to implement move in containers like vector that internally hold a pointer to the data:
The standard wants to leave leeway to implementations to do either. These guarantees are the strongest guarantees it can make while allowing either methods of implementation:
move constructor:
move assignment:
std::vector<foo> vec = std::move(vec);
, which hits -Wmaybe-uninitialized for me) –
Bellerophon © 2022 - 2025 — McMap. All rights reserved.