Given that a
and b
are of type T
, and we have either move construction (T b(move(a));
) or move assignment (b = move(a)
). In what cases do we know what the value of a
will be?
The only one that I know of for sure is unique_ptr
, in which a
will become an empty pointer. Is this also guaranteed for shared_ptr
? Are there any other classes for which the standard guarantees a known value?
Standard library types
From the standard N4296,§17.6.3.1, let's
rv
be an rvalue of typeT
, in Table 20, MoveConstructible requirement and Table 22 MoveAssignable requirement.After operations:
It means that at least your moved object is still in a valid state and can be used as any object of its type. But nothing more is required as a library wide requirement. You have to read specific documentation.
For shared_ptr specificaly :
Fundamental types and trivially copyables
The moved object should be unchanged. I am looking for the confirmation in the standard...
Other types
At least the programmer of a class shall ensures that an object of this class is destructible after it has been moved!