Boost logo

Boost :

Subject: [boost] [outcome] expected<T&>, result<T&>
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2017-05-25 17:33:04


Niall,
Are Boost.Outcome monads intended to work with references (at least lvalue
references)?

If I try to compile the following program that tries to use an `result<T&>`
(on GCC 6.3.1):

```
#include <boost/outcome.hpp>
namespace out = BOOST_OUTCOME_V1_NAMESPACE;

int g_count = 0;

out::result<int&> get_ref()
{
    return out::result<int&>(g_count);
}

int main () {}
```

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.

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?

Regards,
&rzej;


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