Boost logo

Boost :

Subject: Re: [boost] [outcome] expected<T&>, result<T&>
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2017-05-25 22:46:58


2017-05-26 0:29 GMT+02:00 Niall Douglas via Boost <boost_at_[hidden]>:

> On 25/05/2017 18:33, Andrzej Krzemienski via Boost wrote:
> > Niall,
> > Are Boost.Outcome monads intended to work with references (at least
> lvalue
> > references)?
>
> The current code no. And I deliberately left out a static assert until
> feedback came from here.
>
> > I get lots of compiler errors. But the messages ("constructor cannot be
> > overloaded") indicate that it was just an omission and not a design
> > decision.
>
> I did leave my options open just in case. But more support code would be
> needed.
>
> > If I try it with `outcome::expected` I also get these messages, but I
> also
> > get a static assert saying that as per LWG decision T must be default
> > constructible.
> >
> > Vicente, does this mean you cannot use `std::expected` to return
> references?
>
> Neither std::variant nor std::optional support references, and neither
> does std::expected in its current proposal.
>
> Unless reviewers here are super keen on supporting outcome<T&>, I'll be
> adding a static assert forever preventing them soon.
>

But not providing them means that if I have function that returns a
reference and signals failures by, say output function parameter:

```
T& find_smallest(std::array<T, 10> & array, std::error_code & err);
```

I will never be able to "modernize" it to use `outcome` or `expected`.

Regards,
&rzej;


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