do_stuff(my_optional.value())
Is also safe, it throws if the value is absent, the safety check is performed behind the scenes.But people might not want to throw an exception, so
if (my_optional)
do_stuff(*my_optional);
Must also be allowed.
The consequence is someone can also just do do_stuff(*my_optional)
No safety check is done and you get undefined behavior if the value is absent.I don't know rust so I suspect it has a language construct which c++ lacks that prevents you from doing
let Some(obj) = my_optional
do_stuff(obj);