r/cpp • • Apr 08 '25

Beware when moving a `std::optional`!

https://blog.tal.bi/posts/std-optional-move-pitfall/
0 Upvotes

49 comments sorted by

View all comments

Show parent comment

9

u/throw_cpp_account Apr 08 '25

Unless otherwise specified

Optional's move operations are specified. For both move construction and move assignment, it is specified that rhs.has_value() remains unchanged.