Is unique_ptr guaranteed to store nullptr after move?
Yes, you can compare it to nullptr
after the move
and it is guaranteed to compare equal.
From §20.8.1/4 [unique.ptr]
Additionally,
u
can, upon request, transfer ownership to another unique pointeru2
. Upon completion of such a transfer, the following postconditions hold:
—u2.p
is equal to the pre-transferu.p
,
—u.p
is equal tonullptr
, and
...
(the member p
is described earlier as — a unique pointer is an object u
that stores a pointer to a second object p
)
Yes. From C++2011 Standard Section 20.7.1/4:
Additionally, u can, upon request, transfer ownership to another unique pointer u2. Upon completion of such a transfer, the following postconditions hold [...] [the source unique_ptr] is equal to nullptr...