Subject: Re: [boost] [outcome] High level summary of review feedback accepted so far
From: Peter Dimov (lists_at_[hidden])
Date: 2017-05-30 12:25:50
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 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
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.