I am currently looking at implementing a custom container which needs to be compatible with STL algorithms and therefore must meet the C++ container requirements as described here.
In that documentation the Methods and operators
table states, that the expression a = b
has the post condition of a == b
. I am heavily confused by this.
As the table entry for this expression states:
destroys or move-assigns all elements of
a
from elements ofb
To my understanding, moving an object comes with the expectation that the moved object (source object?) will be left in a valid but undefined state. Therefore, the condition a == b
cannot be met in my opinion.
What am I missing here?
The cppreference page is abridged and adapted from the standard for readability. In this case it oversimplifies the requirements, which have to distinguish between the different value categories (as you correctly reasoned). Or maybe the two separate assignment cases (which do not appear consecutively in the table in the standard) have been merged by accident. Either way, cppreference is currently wrong.
Here is what the (current draft) standard says:
http://eel.is/c++draft/containers#container.requirements.general-4
For move-assignment:
Expression:
a = rv
(whererv
is a non-const rvalue)
Return type:X&
Operational Semantics: All existing elements ofa
are either move assigned to or destroyed
Ensures:a
is equal to the value thatrv
had before this assignment
Complexity: linear
For copy-assignment:
Expression:
r = a
Return type:X&
Ensures:r == a
Complexity: linear
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With