beman-project / Optional26

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

is_optional would be more efficient as a variable template #45

Open jwakely opened 1 month ago

jwakely commented 1 month ago

https://github.com/beman-project/Optional26/blob/bfeb9080c0d9c501965ae857a1decf7ed74686f5/include/Beman/Optional26/optional.hpp#L237-L242

There seems to be no reason to prefer a class template to a variable template, it just makes it slower to compile. Why decay_t not remove_cvref_t? Or why do that at all? All uses of is_optional already use either remove_cvref or decay (which should be remove_cvref in all cases), except for the use in optional<T&>::and_then which is probably incorrect.

template <class T>
inline constexpr bool is_optional = false;
template <class T>
inline constexpr bool is_optional<optional<T>> = true;
steve-downey commented 1 month ago

Testing the static_asserts moved up the priority list, too. It was ad-hoc, and therefore wrong.