Subject: Re: [boost] [optional] Safe optional
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2014-11-17 02:29:27


On Sun, 16 Nov 2014 23:04:43 -0800, Andrzej Krzemienski
<akrzemi1_at_[hidden]> wrote:

> Hi Everyone,
> 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"
> things:
> 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.

Number 3 is really not an issue IMO. If you're going to overload operator*
then existing C++ practice dictates that you have to do if(opt) before
dereferencing opt, otherwise you'll have UB.