|
Boost : |
From: Mateusz Loskot (mateusz_at_[hidden])
Date: 2020-01-19 12:19:16
This is a top-post reminding people to please not top-post:
<https://www.boost.org/community/policy.html#quoting>
On Sun, 19 Jan 2020 at 13:02, anshu khare via Boost
<boost_at_[hidden]> wrote:
>
> However when I run
>
> boost::optional<int> i= 5;
> cout << get_optional_value_or(i, 7) ;
>
>
> I get the output as 5.
>
> And when I run
>
> boost::optional<int> i= {};
> cout << get_optional_value_or(i, 7) ;
>
> I get the output as 7.
Correct! This is expected behaviour.
Now, go back to your previous example and compare with the above.
Hint:
int i = {}; // zero
boost::optional<int> v = i;
vs
boost::optional<int> i= {};
May I suggest you to read through the documentation of boost::optional
as well as https://en.cppreference.com/w/cpp/utility/optional,
before you waste more time on experiments to reverse-engineer
what the library is supposed to do?
Best regards,
-- Mateusz Loskot, http://mateusz.loskot.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk