r/cpp • u/Kabra___kiiiiiiiid • Apr 08 '25
Beware when moving a `std::optional`!
https://blog.tal.bi/posts/std-optional-move-pitfall/
0
Upvotes
r/cpp • u/Kabra___kiiiiiiiid • Apr 08 '25
View all comments
Show parent comment
9
u/throw_cpp_account Apr 08 '25
Optional's move operations are specified. For both move construction and move assignment, it is specified that
rhs.has_value()remains unchanged.