|
Boost : |
Subject: Re: [boost] [outcome] High level summary of review feedback accepted so far
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2017-05-27 16:28:39
>> 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();
> }
That's a second approach.
A third approach could be implementing .index() and std::get<>() for
expected.
Niall
-- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk