[libcxx-commits] [libcxx] [libc++] Extend is_trivially_equality_comparable to integral types with the same signdness and size (PR #70344)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 26 08:22:29 PDT 2023
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/70344
None
>From c63e76b882712797d16d8b116558f3e67b66f2f3 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 26 Oct 2023 12:14:11 +0200
Subject: [PATCH] [libc++] Extend is_trivially_equality_comparable to integral
types with the same signdness and size
---
libcxx/include/__type_traits/is_equality_comparable.h | 11 ++++++++++-
.../is_trivially_comparable.compile.pass.cpp | 8 ++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/__type_traits/is_equality_comparable.h b/libcxx/include/__type_traits/is_equality_comparable.h
index e8d3ce87961f148..00316ed637782d3 100644
--- a/libcxx/include/__type_traits/is_equality_comparable.h
+++ b/libcxx/include/__type_traits/is_equality_comparable.h
@@ -10,9 +10,11 @@
#define _LIBCPP___TYPE_TRAITS_IS_EQUALITY_COMPARABLE_H
#include <__config>
+#include <__type_traits/enable_if.h>
#include <__type_traits/integral_constant.h>
#include <__type_traits/is_integral.h>
#include <__type_traits/is_same.h>
+#include <__type_traits/is_signed.h>
#include <__type_traits/is_void.h>
#include <__type_traits/remove_cv.h>
#include <__type_traits/remove_cvref.h>
@@ -44,7 +46,7 @@ struct __is_equality_comparable<_Tp, _Up, __void_t<decltype(std::declval<_Tp>()
// but don't have the same bit-pattern. An exception to this is comparing to a void-pointer. There the bit-pattern is
// always compared.
-template <class _Tp, class _Up>
+template <class _Tp, class _Up, class = void>
struct __libcpp_is_trivially_equality_comparable_impl : false_type {};
template <class _Tp>
@@ -57,6 +59,13 @@ struct __libcpp_is_trivially_equality_comparable_impl<_Tp, _Tp>
};
#endif // __has_builtin(__is_trivially_equality_comparable)
+template <class _Tp, class _Up>
+struct __libcpp_is_trivially_equality_comparable_impl<
+ _Tp,
+ _Up,
+ __enable_if_t<is_integral<_Tp>::value && is_integral<_Up>::value && !is_same<_Tp, _Up>::value &&
+ is_signed<_Tp>::value == is_signed<_Up>::value && sizeof(_Tp) == sizeof(_Up)> > : true_type {};
+
template <class _Tp>
struct __libcpp_is_trivially_equality_comparable_impl<_Tp*, _Tp*> : true_type {};
diff --git a/libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp b/libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
index 3471415f4431166..6875998dc021d41 100644
--- a/libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
+++ b/libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
@@ -6,7 +6,9 @@
//
//===----------------------------------------------------------------------===//
+#include <__type_traits/conditional.h>
#include <__type_traits/is_equality_comparable.h>
+#include <__type_traits/is_signed.h>
enum Enum : int {};
enum class EnumClass : int {};
@@ -38,6 +40,12 @@ static_assert(!std::__libcpp_is_trivially_equality_comparable<float, float>::val
static_assert(!std::__libcpp_is_trivially_equality_comparable<double, double>::value, "");
static_assert(!std::__libcpp_is_trivially_equality_comparable<long double, long double>::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable<
+ char,
+ typename std::conditional<std::is_signed<char>::value, signed char, unsigned char>::type>::value,
+ "");
+static_assert(std::__libcpp_is_trivially_equality_comparable<char16_t, unsigned short>::value, "");
+
struct S {
char c;
};
More information about the libcxx-commits
mailing list