Subject: [boost] [optional] Safe optional
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2014-11-17 02:04:43
I would like to run an idea through everyone in this list. There is a
recurring complaint about Boost.Optional that it allows you to do "unsafe"
1. Inadvertent mixed comparisons between T and optional<T>
2. Unintended conversion from T to optional<T>
3. "Unchecked" access to the contained object, which causes an UB when
performed on an uninitialized optional object.
There are valid reasons why optional is defined the way it is defined. But
at the same time the complaints above are also valid. This makes some
people abandon Boost.Optional and use their own alternative.
My idea is to provide another type wrapper, say safe_optional<T>, that
would choose different tradeoffs: prefer "safety" to some flexibility
and/or efficiency. It would probably be part of Boost.Optional library as
the implementation can be reused - only the interface would be changed.
One downside of this solution is that we would have two libraries for doing
nearly the same thing, which could "scatter" the community. There is a
value for standardizing certain things and making them universal.
I would like to solicit your feedback.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk