[libcxx-commits] [libcxx] [libc++][NFC] Simplify the implementation of `__promote` (PR #81379)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jun 6 22:57:36 PDT 2024
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/81379
>From bb27796aa572478dd77559be2883869d9b21fd66 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sat, 10 Feb 2024 13:22:25 +0100
Subject: [PATCH] [libc++][NFC] Simplify the implementation of `__promote`
---
libcxx/include/__type_traits/promote.h | 42 +++++++++++++++++++++++---
1 file changed, 38 insertions(+), 4 deletions(-)
diff --git a/libcxx/include/__type_traits/promote.h b/libcxx/include/__type_traits/promote.h
index e22b4a422c2c8..2b2a6843b9150 100644
--- a/libcxx/include/__type_traits/promote.h
+++ b/libcxx/include/__type_traits/promote.h
@@ -11,8 +11,12 @@
#include <__config>
#include <__type_traits/integral_constant.h>
-#include <__type_traits/is_same.h>
-#include <__utility/declval.h>
+#include <__type_traits/is_arithmetic.h>
+
+#if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER == 1700
+# include <__type_traits/is_same.h>
+# include <__utility/declval.h>
+#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -20,6 +24,34 @@
_LIBCPP_BEGIN_NAMESPACE_STD
+// TODO(LLVM-20): Remove this workaround
+#if !defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER != 1700
+
+template <class... _Args>
+class __promote {
+ static_assert((is_arithmetic<_Args>::value && ...));
+
+ static float __test(float);
+ static double __test(char);
+ static double __test(int);
+ static double __test(unsigned);
+ static double __test(long);
+ static double __test(unsigned long);
+ static double __test(long long);
+ static double __test(unsigned long long);
+# ifndef _LIBCPP_HAS_NO_INT128
+ static double __test(__int128_t);
+ static double __test(__uint128_t);
+# endif
+ static double __test(double);
+ static long double __test(long double);
+
+public:
+ using type = decltype((__test(_Args()) + ...));
+};
+
+#else
+
template <class _Tp>
struct __numeric_type {
static void __test(...);
@@ -31,10 +63,10 @@ struct __numeric_type {
static double __test(unsigned long);
static double __test(long long);
static double __test(unsigned long long);
-#ifndef _LIBCPP_HAS_NO_INT128
+# ifndef _LIBCPP_HAS_NO_INT128
static double __test(__int128_t);
static double __test(__uint128_t);
-#endif
+# endif
static double __test(double);
static long double __test(long double);
@@ -89,6 +121,8 @@ class __promote_imp<_A1, void, void, true> {
template <class _A1, class _A2 = void, class _A3 = void>
class __promote : public __promote_imp<_A1, _A2, _A3> {};
+#endif // !defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER >= 1700
+
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___TYPE_TRAITS_PROMOTE_H
More information about the libcxx-commits
mailing list