Skip to content

Commit c8992fb

Browse files
authored
[libc++][NFC] Simplify the implementation of __promote (#81379)
This depends on enabling the use of extensions.
1 parent 6834e6d commit c8992fb

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

libcxx/include/__type_traits/promote.h

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,47 @@
1111

1212
#include <__config>
1313
#include <__type_traits/integral_constant.h>
14-
#include <__type_traits/is_same.h>
15-
#include <__utility/declval.h>
14+
#include <__type_traits/is_arithmetic.h>
15+
16+
#if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER == 1700
17+
# include <__type_traits/is_same.h>
18+
# include <__utility/declval.h>
19+
#endif
1620

1721
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1822
# pragma GCC system_header
1923
#endif
2024

2125
_LIBCPP_BEGIN_NAMESPACE_STD
2226

27+
// TODO(LLVM-20): Remove this workaround
28+
#if !defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER != 1700
29+
30+
template <class... _Args>
31+
class __promote {
32+
static_assert((is_arithmetic<_Args>::value && ...));
33+
34+
static float __test(float);
35+
static double __test(char);
36+
static double __test(int);
37+
static double __test(unsigned);
38+
static double __test(long);
39+
static double __test(unsigned long);
40+
static double __test(long long);
41+
static double __test(unsigned long long);
42+
# ifndef _LIBCPP_HAS_NO_INT128
43+
static double __test(__int128_t);
44+
static double __test(__uint128_t);
45+
# endif
46+
static double __test(double);
47+
static long double __test(long double);
48+
49+
public:
50+
using type = decltype((__test(_Args()) + ...));
51+
};
52+
53+
#else
54+
2355
template <class _Tp>
2456
struct __numeric_type {
2557
static void __test(...);
@@ -31,10 +63,10 @@ struct __numeric_type {
3163
static double __test(unsigned long);
3264
static double __test(long long);
3365
static double __test(unsigned long long);
34-
#ifndef _LIBCPP_HAS_NO_INT128
66+
# ifndef _LIBCPP_HAS_NO_INT128
3567
static double __test(__int128_t);
3668
static double __test(__uint128_t);
37-
#endif
69+
# endif
3870
static double __test(double);
3971
static long double __test(long double);
4072

@@ -89,6 +121,8 @@ class __promote_imp<_A1, void, void, true> {
89121
template <class _A1, class _A2 = void, class _A3 = void>
90122
class __promote : public __promote_imp<_A1, _A2, _A3> {};
91123

124+
#endif // !defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER >= 1700
125+
92126
_LIBCPP_END_NAMESPACE_STD
93127

94128
#endif // _LIBCPP___TYPE_TRAITS_PROMOTE_H

0 commit comments

Comments
 (0)