Boost logo

Boost :

Subject: Re: [boost] [optional] Why was optional<T>::reset() deprecated?
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2016-03-04 03:06:26

2016-03-04 3:14 GMT+01:00 Gavin Lambert <gavinl_at_[hidden]>:

> On 2/03/2016 11:51, Andrzej Krzemienski wrote:
>> At some earlier stages of development, boost::optional did not have the
>> assignment from boost::none_t (and probably also from T); and reset was
>> the
>> only way to efficiently change the optional from the state of having the
>> value to the state of not having the value.
>> After the addition of more fancy syntax (conversion to bool, assignment
>> from none_t), reset() (and is_initialized()) became redundant, and hence
>> the deprecation.
> It still bothers me a bit that none and nullptr are separate. Do we
> really need two different ways to spell "nothing"?
> I suppose there is a use case for optional<some-pointer-type> which could
> have distinct states for "no pointer" vs. "null pointer" vs. "valid
> pointer", but how often do you really need to distinguish the first two
> states?
> (Although I guess if you didn't want to distinguish them, you'd just use
> some-pointer-type directly instead of wrapping it in an optional. So I
> understand the presumed rationale, it just seems weird.)

See here for an extended rationale for not using nullptr in std::optional:

This rationale apart, I would argue that nullptr does not say "nothing" but
"no pointer (of any type)".

But then, you are probably right that this dilemma is not really faced by
the programmers very often.


Boost list run by bdawes at, gregod at, cpdaniel at, john at