Boost logo

Boost :

Subject: Re: [boost] [optional] get() misses optional r-value overload in contrast to operator* and value()
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2018-03-23 16:40:32


On Fri, Mar 23, 2018 at 12:01 PM, Peter Dimov via Boost
<boost_at_[hidden]> wrote:
> Andrzej Krzemienski wrote:
>
>> > const auto& x = func0().value();
>
> ...
>>
>> I am convinced that you are hitting an UB. Temporary returned by func0()
>> is destroyed in the first line.
>
>
> Interesting question. value() && returns T&&. The auto const& reference
> can't bind directly to T&&, because that's not an lvalue.

An lvalue-reference-to-const can bind to an rvalue (it's why you can
pass an rvalue to a function that takes a "const T&").

-- 
-Matt Calabrese

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