optional icon indicating copy to clipboard operation
optional copied to clipboard

The converting optional<U> constructor only works with optional<const T&>

Open steve-downey opened this issue 1 year ago • 0 comments

    base b{1};
    derived d(1, 2);

    tl::optional<base&> b3{d2}; // error
    tl::optional<const base&> b3a{d2}; // works

The optional is deep const, so when rhs is called with an optional<U>const& the type is U const&, and the delegated constructor can't convert the addressof(u) to a T

Illustration here: https://godbolt.org/z/sTEr1cfd6

Comparison with boost::optional : https://godbolt.org/z/T1EYcjv71

steve-downey avatar Sep 29 '23 21:09 steve-downey