Boost logo

Boost :

Subject: Re: [boost] [review] Review of Outcome (starts Fri-19-May)
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2017-05-23 17:32:06


Le 23/05/2017 à 12:35, Andrzej Krzemienski via Boost a écrit :
> 2017-05-23 8:50 GMT+02:00 Andrzej Krzemienski <akrzemi1_at_[hidden]>:
>
>>
>> 2017-05-23 1:56 GMT+02:00 Jared Wyles via Boost <boost_at_[hidden]>:
>>
>>> Hello,
>>>
>>> One of the questions that is inevitably asked when a proposal to switch to
>>> using something like outcome is that of exceptions. Why outcome over
>>> exceptions etc which you briefly touch on in your ACUU talk. With that in
>>> mind, when attempting to sell this library having the motivating example
>>> on
>>> the boost.outcome docs using exceptions really makes starting the
>>> discussion
>>> harder. I understand one can never escape exceptions, but it shouldn't be
>>> used as the first example a new user sees. I would like to see this
>>> example
>>> updated to show how to handle errors with out the need for exception
>>> handling around accessing *value*. Personally, I see something similar to
>>> https://ned14.github.io/boost.outcome/md_doc_md_03-tutorial_
>>> b.html#expected_payload
>>> as a much better example to help sell outcome and therefore better suited
>>> as
>>> the motivating example for the front page of the docs.
>>>
>> This means, the initial example should use `boost::outcome::result`
>> (instead of `boost::outcome::outcome`). And then function that inspects the
>> result could read:
>>
>> ```
>> void test()
>> {
>> if (auto r = fun)
>> use_int_value(r.value());
>> else
>> inspect_error_code(r.error());
>> }
>> ```
>>
> The initial example could look like this:
> https://github.com/akrzemi1/__sandbox__/blob/master/outcome_intro.md
>
THis is a better example of what Outcome can do, yes.

Would the following works as well? I have changed just outcome by expected.
What if fun returns an expection ptr?

auto my_fun()noexcept
   -> outcome::expected<int>
{
   std::error_code ec;
   int i =Library1::fun(ec);
   if (ec)
     return outcome::make_errored_outcome(ec);// error code returned inside outcome
     
   BOOST_OUTCOME_TRY(rslt2,Library2::fun());// if fun() succeeds, rslt2 of type int contains result
                                                // otherwise returns the result of fun() up
                                                           
   BOOST_OUTCOME_TRY(rslt3,Library3::fun());// Similarly, either rslt3 is an int with successful result,
                                                // or my_fun() returns what Library3::fun() has returned

   return i + rslt3;// return a result with a value
};

Best,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk