Subject: Re: [boost] [outcome] High level summary of review feedback accepted so far
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2017-06-03 08:39:58
Le 27/05/2017 Ã 16:24, Peter Dimov via Boost a Ã©crit :
> Niall Douglas wrote:
>> I would assume an expected<T, E1, .., En> could only return a
>> std::variant<E1, ..., En> from its .error(). I can't think what else
>> it could do.
> As the foremost authority on the nonexistent expected<T, E...>, I can
> tell you what it does:
> // F shall be in E...
> template<class F> bool has_error() const;
> template<class F> F error() const;
> // if sizeof...(E) == 1
> bool has_error() const;
> E1 error() const;
> It returns the equivalent of variant<E...> not from error(), but from
> unexpected<E...> unexpected() const;
> which allows you to
> expected<T, E1, E2, E3> function()
> expected<U, E1, E2> e1 = function1();
> if( !e1 ) return e1.unexpected();
> expected<V, E3> e2 = function2();
> if( !e2 ) return e2.unexpected();
> return e1.value() + e2.value();
Yes this is the reason d'Ãªtre fro the unexpected function.
I see that the implementation you have done don't allows to return it by
reference, and I was wondering if the variant2::subset function (which
could for usability purposes be a non-member function) couldn't return
I know that this is something related to changes to the standard. There
is currently a thread on C++-Core about the whether it is UB to cast a
type to another with a common layout in order to access the common
members. It seems that this is valid in C, but this is not anymore valid
in C++. If at the end this kind of casts were valid as well in C++, I
believe that we could return subset/unexpected by reference without UB.
Note that a variant with less alternatives than another one has the
"same shared representation".