Subject: Re: [boost] [outcome] High level summary of review feedback accepted so far
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2017-05-30 20:05:57
2017-05-30 14:25 GMT+02:00 Peter Dimov via Boost <boost_at_[hidden]>:
> Niall Douglas wrote:
> > value() id wide operator*() is narrow.
>> Why? Just because optional made that mistake?
> The motivation here is that in
> if( o )
> there is needless replication of the check. This, as I already mentioned,
> stems from a desire to operate on the value inside 'o' directly, which is
> not my preferred style in result's case, where I'd prefer to extract it
> There is a middle ground here, which I was pondering for a while, make
> has_value return T* instead of bool.
> T* has_value();
> T const* has_value() const;
> Returns: a pointer to the contained value if one is present, otherwise
> Now the above sequence is spelled
> if( auto* p = o.has_value() )
> Not sure I particularly like that, but for people who like "consistency
> with X" arguments, this is like variant's get_if, whereas value() is like
> variant's get().
> This still allows the ordinary if( r.has_value() ) check to work as-is, so
> nothing is lost in principle.
> But if this has_value signature strikes you as a bit too novel, the more
> traditional T* value_if() is also an option. Note how it strikes a balance
> where the function itself has a wide contract, but then if you use the
> returned pointer without a check you're on your own.
I like that.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk