How do you actually take a value out of optional? Meaning take ownership of the value inside the std::optional
and replace it with std::nullopt
(or swap it with another value)?
In Rust for example you could .unwrap
your Option
or do something like foo.take().unwrap()
. I'm trying to do something like that with C++ optional
s.
opt
still contains (moved-from) value after that. Ideally you should follow-up with.reset()
. Also, tangential, but*std::move(opt)
andstd::move(*opt)
are equivalent. – Flinders