In the comments on Andrzej's move constructor article, I posted that a moved from object can have any member function called on it that does not have a pre-condition. I gave the example std::vector::front
as a function that you cannot call on a moved-from std::vector
because it has the pre-condition that the vector is not empty. I gave the examples of std::vector::empty
, std::vector::push_back
, and std::vector::reserve
as functions that you can (but shouldn't) call on a moved-from std::vector
, because they have no pre-conditions.
However, that got me thinking. std::vector::push_back
requires that there is enough contiguous memory available on the host system. This isn't so much a requirement on the std::vector
object as it is about the system it is running on, but that still seems to me to be a pre-condition.
What is the context of move constructors leaving an object in a valid but unspecified state, and does it apply to potential out-of-memory situations with std::vector::push_back
? In particular, if std::vector::push_back
would have worked prior to a move, is it guaranteed to work after (ignoring issues such as other processes using up memory)?
For reference: § 17.6.3.1
Table 20 — MoveConstructible requirements [moveconstructible]
Expression Post-condition
T u = rv; u is equivalent to the value of rv before the construction
T(rv) T(rv) is equivalent to the value of rv before the construction
rv’s state is unspecified [ Note:rv must still meet the requirements of the library compo-
nent that is using it. The operations listed in those requirements must work as specified
whether rv has been moved from or not. — end note ]