TartanLlama / optional

C++11/14/17 std::optional with functional-style extensions and reference support
https://tl.tartanllama.xyz
Creative Commons Zero v1.0 Universal
859 stars 67 forks source link

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

Open steve-downey opened 1 year ago

steve-downey commented 1 year ago
    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 optionalconst& 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