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

`tl::optional<T&>` should be constructible from a `tl::optional<T>`. #57

Open BenFrantzDale opened 2 years ago

BenFrantzDale commented 2 years ago

To me the biggest use of optional<T&> is in arguments like void foo(optional<const Heavy&>) where the naive void foo1(const optional<Heavy>&) of course means foo1(heavy) has to copy the heavy to a optional<Heavy>. Of course, if I have an optional<Heavy> optHeavy I can call foo1(optHeavy), but if I call foo(optHeavy), tl::optional won't implicitly convert from const optional<Heavy> to optional<const Heavy&>.

That is, I'd like optional<T&> to be constructible from optional<T>. That would let foo(optHeavy) Just Work. (Or maybe just let optional<const T&> construct from const optional<T>&?)