Subject: Re: [boost] [optional] Safe optional
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2014-11-17 05:12:40
On Sun, 16 Nov 2014 23:04:43 -0800, Andrzej Krzemienski
> 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
> 1. Inadvertent mixed comparisons between T and optional<T>
> 2. Unintended conversion from T to optional<T>
The problem with optional is that it tries to be a drop-in replacement
proxy for its underlying type, and, unfortunately, it can't fully do that.
So it ends up with an identity crisis. IMO, optional should be treated as
a first class object, not a thin wrapper around T, that means no implicit
conversions to/from T, no implicit comparisons with T, etc... Last time I
looked at this, that will solve the reference rebinding gotcha. That is,
you'll have one behavior for optional<T> and optional<T&>. It will also
solve the following gotcha too:
if(b == true)
// Does not get executed.
std::cout << "???\n";
// Gets executed.
std::cout << "!!!\n";
which I believe to be an ever bigger problem.
In short, and IMHO optional should be a true model of the pointer concept,
like iterators and shared_ptr.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk