|
Boost : |
Subject: Re: [boost] [outcome] where is the monadic style tutorial?
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2017-06-02 08:31:36
2017-06-01 13:53 GMT+02:00 Mathias Gaunard via Boost <boost_at_[hidden]>
:
> Ok so the approach is to do
>
> auto expected1 = do_statement1();
> if (!expected1) return expected1;
> auto expected1_value = expected1.value();
>
> auto expected2 = do_statement2(expected1_value);
> if (!expected2) return expected2;
> auto expected2_value = expected2.value();
>
> return do_statement3(expected2_value);
>
> with that logic being encoded by the TRY macros?
>
> I'd rather use continuation passing style, was that considered?
>
> return
> expected_flow(do_statement1)
> >> [](auto const& expected1_value)
> {
> return do_statement2(expected1_value);
> }
> >> [](auto const& expected2_value)
> {
> return do_statement3(expected2_value);
> }
> ;
>
Does this solution scale to more complicated control flows?
How would the following flow be represented by this style?
```
auto rslt1 = fun1();
RETURN_IF_FAILED(rslt1);
auto rslt2 = fun2();
RETURN_IF_FAILED(rslt2);
auto rslt3 = fun3(rslt2);
RETURN_IF_FAILED(rslt3);
return fun4(rslt1, rslt3)
```
Regards,
&rzej;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk