variant: Use concepts
This makes the code a little more concise and removes the need for extra
template parameters.
Change-Id: Ie990ec27eb99e15a2b7d12175f4afab473fa049b
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/include/stdplus/variant.hpp b/include/stdplus/variant.hpp
index 61d2e27..fe849da 100644
--- a/include/stdplus/variant.hpp
+++ b/include/stdplus/variant.hpp
@@ -1,3 +1,6 @@
+#include <stdplus/concepts.hpp>
+
+#include <concepts>
#include <type_traits>
#include <utility>
#include <variant>
@@ -7,19 +10,17 @@
namespace detail
{
-template <template <typename, typename, typename = void> typename Veq,
- typename...>
+template <template <typename, typename> typename Veq, typename...>
struct CanVeq;
-template <template <typename, typename, typename = void> typename Veq,
- typename T>
+template <template <typename, typename> typename Veq, typename T>
struct CanVeq<Veq, T>
{
static constexpr inline bool value = false;
};
-template <template <typename, typename, typename = void> typename Veq,
- typename T, typename V, typename... Vs>
+template <template <typename, typename> typename Veq, typename T, typename V,
+ typename... Vs>
struct CanVeq<Veq, T, V, Vs...>
{
static constexpr inline bool value = Veq<T, V>::value ||
@@ -37,14 +38,12 @@
}
};
-template <typename T1, typename T2, typename = void>
+template <typename T1, typename T2>
struct VeqFuzzy : VeqBase<T1, T2>
{};
-template <typename T1, typename T2>
-struct VeqFuzzy<T1, T2,
- std::enable_if_t<std::is_same_v<
- decltype(std::declval<T1>() == std::declval<T2>()), bool>>>
+template <typename T1, WeaklyEqualityComparableWith<T1> T2>
+struct VeqFuzzy<T1, T2>
{
static constexpr inline bool value = true;
@@ -54,12 +53,12 @@
}
};
-template <typename T1, typename T2, typename = void>
+template <typename T1, typename T2>
struct VeqStrict : VeqBase<T1, T2>
{};
-template <typename T1, typename T2>
-struct VeqStrict<T1, T2, std::enable_if_t<std::is_same_v<T1, T2>>>
+template <typename T1, std::same_as<T1> T2>
+struct VeqStrict<T1, T2>
{
static constexpr inline bool value = true;
@@ -71,8 +70,8 @@
} // namespace detail
-template <template <typename, typename, typename = void> typename Veq,
- typename... Vs, typename T,
+template <template <typename, typename> typename Veq, typename... Vs,
+ typename T,
std::enable_if_t<detail::CanVeq<Veq, T, Vs...>::value, bool> = true>
constexpr bool variantEq(const std::variant<Vs...>& vs, const T& t) noexcept
{
@@ -83,8 +82,8 @@
vs);
}
-template <template <typename, typename, typename = void> typename Veq,
- typename... Vs, typename... Vs2>
+template <template <typename, typename> typename Veq, typename... Vs,
+ typename... Vs2>
constexpr bool variantEq(const std::variant<Vs...>& vs,
const std::variant<Vs2...>& vs2) noexcept
{