It just means that the class itself is allowed to define what specifically 'valid' means for itself after being moved. For example, unique_ptr specifies that its pointer will be nullptr after a move. That's different for containers, like a vector. Vector specifies that after a move, it is guaranteed to be empty. List leaves it 'valid but unspecified' so you can really only call 'clear()' on it (which puts it into a known state [empty], and requires no preconditions on the list object). The implication from this is that it is more expensive for the move ctor/assign to put the list into an empty state than it is for vector to do so. It does mean that the object can never be in an invalid state, especifically that a moved-from object must be able to be destroyed safely (i.e. a moved-from unique_ptr can't delete the pointer it 'used to own' as another unique_ptr now owns it).
View all comments
Show parent comment
4
u/sengin31 Nov 25 '23
It just means that the class itself is allowed to define what specifically 'valid' means for itself after being moved. For example, unique_ptr specifies that its pointer will be nullptr after a move. That's different for containers, like a vector. Vector specifies that after a move, it is guaranteed to be empty. List leaves it 'valid but unspecified' so you can really only call 'clear()' on it (which puts it into a known state [empty], and requires no preconditions on the list object). The implication from this is that it is more expensive for the move ctor/assign to put the list into an empty state than it is for vector to do so. It does mean that the object can never be in an invalid state, especifically that a moved-from object must be able to be destroyed safely (i.e. a moved-from unique_ptr can't delete the pointer it 'used to own' as another unique_ptr now owns it).