beman-project / optional26

Beman.Optional26: `std::optional` extensions targeting C++26
Apache License 2.0
13 stars 8 forks source link

is-optional needs to test for derived optionals #51

Open steve-downey opened 1 month ago

steve-downey commented 1 month ago

Avoids an infinite recursion in comparison operators. Fixed in standard.

namespace detail {
template <class T>
    concept is_optional = requires(const T& t) { // exposition only
    []<class U>(const optional<U>&) {}(t);
};

TODO: add test cases inheriting from optional.

Note - Bloomberg actually ran into this with moving to C++20 and spaceship synthesis of comparison operators, and one of our nullable types.