I noticed today that boost::optional::is_initialized()
is marked as deprecated in the Boost 1.64.0 reference. My projects are liberally sprinkled with is_initialized()
to check if the boost::optional
contains a value.
I don't see any other way to properly test if a boost::optional
is initialized, am I missing something?
The boost::optional
has a explicit operator bool()
, meaning that I can do if(foo){...}
if foo
is a boost::optional
. However, this would give wrong results if foo
is a boost::optional<bool>
or some other boost::optional<T>
where T
is convertible to bool
.
What does Boost expect users to do?
boost::none
? As is done in quite a few places in the Boost optional manual?boost::optional<bool>
? For theboost::optional<bool> a
if(a)
gives an initialization status.*a
-a
value if initializedboost::none
.