Skip to content

Commit 276e1b8

Browse files
committed
[libc++] Simplify __promote
1 parent 62d32c2 commit 276e1b8

File tree

15 files changed

+57
-66
lines changed

15 files changed

+57
-66
lines changed

libcxx/include/__math/copysign.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace __math {
3333
}
3434

3535
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
36-
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type copysign(_A1 __x, _A2 __y) _NOEXCEPT {
36+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> copysign(_A1 __x, _A2 __y) _NOEXCEPT {
3737
return ::__builtin_copysign(__x, __y);
3838
}
3939

libcxx/include/__math/exponential_functions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double pow(long double __x, long double __y) _
158158
}
159159

160160
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
161-
inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type pow(_A1 __x, _A2 __y) _NOEXCEPT {
162-
using __result_type = typename __promote<_A1, _A2>::type;
161+
inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> pow(_A1 __x, _A2 __y) _NOEXCEPT {
162+
using __result_type = __promote_t<_A1, _A2>;
163163
static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
164164
return __math::pow((__result_type)__x, (__result_type)__y);
165165
}

libcxx/include/__math/fdim.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double fdim(long double __x, long double __y)
3535
}
3636

3737
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
38-
inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fdim(_A1 __x, _A2 __y) _NOEXCEPT {
39-
using __result_type = typename __promote<_A1, _A2>::type;
38+
inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> fdim(_A1 __x, _A2 __y) _NOEXCEPT {
39+
using __result_type = __promote_t<_A1, _A2>;
4040
static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
4141
return __math::fdim((__result_type)__x, (__result_type)__y);
4242
}

libcxx/include/__math/fma.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ template <class _A1,
4040
class _A2,
4141
class _A3,
4242
__enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value && is_arithmetic<_A3>::value, int> = 0>
43-
inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2, _A3>::type fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT {
44-
using __result_type = typename __promote<_A1, _A2, _A3>::type;
43+
inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2, _A3> fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT {
44+
using __result_type = __promote_t<_A1, _A2, _A3>;
4545
static_assert(
4646
!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value && _IsSame<_A3, __result_type>::value),
4747
"");

libcxx/include/__math/hypot.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double hypot(long double __x, long double __y)
4343
}
4444

4545
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
46-
inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type hypot(_A1 __x, _A2 __y) _NOEXCEPT {
47-
using __result_type = typename __promote<_A1, _A2>::type;
46+
inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> hypot(_A1 __x, _A2 __y) _NOEXCEPT {
47+
using __result_type = __promote_t<_A1, _A2>;
4848
static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
4949
return __math::hypot((__result_type)__x, (__result_type)__y);
5050
}
@@ -91,8 +91,8 @@ template <class _A1,
9191
class _A2,
9292
class _A3,
9393
std::enable_if_t< is_arithmetic_v<_A1> && is_arithmetic_v<_A2> && is_arithmetic_v<_A3>, int> = 0 >
94-
_LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2, _A3>::type hypot(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT {
95-
using __result_type = typename __promote<_A1, _A2, _A3>::type;
94+
_LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2, _A3> hypot(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT {
95+
using __result_type = __promote_t<_A1, _A2, _A3>;
9696
static_assert(!(
9797
std::is_same_v<_A1, __result_type> && std::is_same_v<_A2, __result_type> && std::is_same_v<_A3, __result_type>));
9898
return __math::__hypot(

libcxx/include/__math/inverse_trigonometric_functions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double atan2(long double __y, long double __x)
8686
}
8787

8888
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
89-
inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type atan2(_A1 __y, _A2 __x) _NOEXCEPT {
90-
using __result_type = typename __promote<_A1, _A2>::type;
89+
inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> atan2(_A1 __y, _A2 __x) _NOEXCEPT {
90+
using __result_type = __promote_t<_A1, _A2>;
9191
static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
9292
return __math::atan2((__result_type)__y, (__result_type)__x);
9393
}

libcxx/include/__math/min_max.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ template <class = int>
3939
}
4040

4141
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
42-
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmax(_A1 __x, _A2 __y) _NOEXCEPT {
43-
using __result_type = typename __promote<_A1, _A2>::type;
42+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> fmax(_A1 __x, _A2 __y) _NOEXCEPT {
43+
using __result_type = __promote_t<_A1, _A2>;
4444
static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
4545
return __math::fmax((__result_type)__x, (__result_type)__y);
4646
}
@@ -61,8 +61,8 @@ template <class = int>
6161
}
6262

6363
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
64-
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmin(_A1 __x, _A2 __y) _NOEXCEPT {
65-
using __result_type = typename __promote<_A1, _A2>::type;
64+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> fmin(_A1 __x, _A2 __y) _NOEXCEPT {
65+
using __result_type = __promote_t<_A1, _A2>;
6666
static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
6767
return __math::fmin((__result_type)__x, (__result_type)__y);
6868
}

libcxx/include/__math/modulo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double fmod(long double __x, long double __y)
3737
}
3838

3939
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
40-
inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmod(_A1 __x, _A2 __y) _NOEXCEPT {
41-
using __result_type = typename __promote<_A1, _A2>::type;
40+
inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> fmod(_A1 __x, _A2 __y) _NOEXCEPT {
41+
using __result_type = __promote_t<_A1, _A2>;
4242
static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
4343
return __math::fmod((__result_type)__x, (__result_type)__y);
4444
}

libcxx/include/__math/remainder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double remainder(long double __x, long double
3737
}
3838

3939
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
40-
inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type remainder(_A1 __x, _A2 __y) _NOEXCEPT {
41-
using __result_type = typename __promote<_A1, _A2>::type;
40+
inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> remainder(_A1 __x, _A2 __y) _NOEXCEPT {
41+
using __result_type = __promote_t<_A1, _A2>;
4242
static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
4343
return __math::remainder((__result_type)__x, (__result_type)__y);
4444
}
@@ -59,8 +59,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double remquo(long double __x, long double __y
5959
}
6060

6161
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
62-
inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT {
63-
using __result_type = typename __promote<_A1, _A2>::type;
62+
inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT {
63+
using __result_type = __promote_t<_A1, _A2>;
6464
static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
6565
return __math::remquo((__result_type)__x, (__result_type)__y, __z);
6666
}

libcxx/include/__math/rounding_functions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double nextafter(long double __x, long double
158158
}
159159

160160
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
161-
inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type nextafter(_A1 __x, _A2 __y) _NOEXCEPT {
162-
using __result_type = typename __promote<_A1, _A2>::type;
161+
inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> nextafter(_A1 __x, _A2 __y) _NOEXCEPT {
162+
using __result_type = __promote_t<_A1, _A2>;
163163
static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
164164
return __math::nextafter((__result_type)__x, (__result_type)__y);
165165
}

libcxx/include/__math/traits.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,47 +145,47 @@ template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
145145

146146
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
147147
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
148-
using type = typename __promote<_A1, _A2>::type;
148+
using type = __promote_t<_A1, _A2>;
149149
return __builtin_isgreater((type)__x, (type)__y);
150150
}
151151

152152
// isgreaterequal
153153

154154
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
155155
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
156-
using type = typename __promote<_A1, _A2>::type;
156+
using type = __promote_t<_A1, _A2>;
157157
return __builtin_isgreaterequal((type)__x, (type)__y);
158158
}
159159

160160
// isless
161161

162162
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
163163
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT {
164-
using type = typename __promote<_A1, _A2>::type;
164+
using type = __promote_t<_A1, _A2>;
165165
return __builtin_isless((type)__x, (type)__y);
166166
}
167167

168168
// islessequal
169169

170170
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
171171
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
172-
using type = typename __promote<_A1, _A2>::type;
172+
using type = __promote_t<_A1, _A2>;
173173
return __builtin_islessequal((type)__x, (type)__y);
174174
}
175175

176176
// islessgreater
177177

178178
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
179179
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
180-
using type = typename __promote<_A1, _A2>::type;
180+
using type = __promote_t<_A1, _A2>;
181181
return __builtin_islessgreater((type)__x, (type)__y);
182182
}
183183

184184
// isunordered
185185

186186
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
187187
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
188-
using type = typename __promote<_A1, _A2>::type;
188+
using type = __promote_t<_A1, _A2>;
189189
return __builtin_isunordered((type)__x, (type)__y);
190190
}
191191

libcxx/include/__type_traits/promote.h

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,30 @@
1010
#define _LIBCPP___TYPE_TRAITS_PROMOTE_H
1111

1212
#include <__config>
13-
#include <__type_traits/integral_constant.h>
14-
#include <__type_traits/is_arithmetic.h>
1513

1614
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1715
# pragma GCC system_header
1816
#endif
1917

2018
_LIBCPP_BEGIN_NAMESPACE_STD
2119

22-
template <class... _Args>
23-
class __promote {
24-
static_assert((is_arithmetic<_Args>::value && ...));
25-
26-
static float __test(float);
27-
static double __test(char);
28-
static double __test(int);
29-
static double __test(unsigned);
30-
static double __test(long);
31-
static double __test(unsigned long);
32-
static double __test(long long);
33-
static double __test(unsigned long long);
20+
float __promote_impl(float);
21+
double __promote_impl(char);
22+
double __promote_impl(int);
23+
double __promote_impl(unsigned);
24+
double __promote_impl(long);
25+
double __promote_impl(unsigned long);
26+
double __promote_impl(long long);
27+
double __promote_impl(unsigned long long);
3428
#if _LIBCPP_HAS_INT128
35-
static double __test(__int128_t);
36-
static double __test(__uint128_t);
29+
double __promote_impl(__int128_t);
30+
double __promote_impl(__uint128_t);
3731
#endif
38-
static double __test(double);
39-
static long double __test(long double);
32+
double __promote_impl(double);
33+
long double __promote_impl(long double);
4034

41-
public:
42-
using type = decltype((__test(_Args()) + ...));
43-
};
35+
template <class... _Args>
36+
using __promote_t = decltype((__promote_impl(_Args()) + ...));
4437

4538
_LIBCPP_END_NAMESPACE_STD
4639

libcxx/include/cmath

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr long double lerp(long double __a, long do
599599
}
600600

601601
template <class _A1, class _A2, class _A3>
602-
inline _LIBCPP_HIDE_FROM_ABI constexpr
603-
typename enable_if_t< is_arithmetic<_A1>::value && is_arithmetic<_A2>::value && is_arithmetic<_A3>::value,
604-
__promote<_A1, _A2, _A3> >::type
605-
lerp(_A1 __a, _A2 __b, _A3 __t) noexcept {
606-
typedef typename __promote<_A1, _A2, _A3>::type __result_type;
602+
requires(is_arithmetic_v<_A1> && is_arithmetic_v<_A2> && is_arithmetic_v<_A3>)
603+
_LIBCPP_HIDE_FROM_ABI inline constexpr __promote_t<_A1, _A2, _A3> lerp(_A1 __a, _A2 __b, _A3 __t) noexcept {
604+
using __result_type = __promote_t<_A1, _A2, _A3>;
607605
static_assert(!(
608606
_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value && _IsSame<_A3, __result_type>::value));
609607
return std::__lerp((__result_type)__a, (__result_type)__b, (__result_type)__t);

libcxx/include/complex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,21 +1101,21 @@ inline _LIBCPP_HIDE_FROM_ABI complex<_Tp> pow(const complex<_Tp>& __x, const com
11011101
}
11021102

11031103
template <class _Tp, class _Up, __enable_if_t<is_floating_point<_Tp>::value && is_floating_point<_Up>::value, int> = 0>
1104-
inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type>
1104+
inline _LIBCPP_HIDE_FROM_ABI complex<__promote_t<_Tp, _Up> >
11051105
pow(const complex<_Tp>& __x, const complex<_Up>& __y) {
1106-
typedef complex<typename __promote<_Tp, _Up>::type> result_type;
1106+
typedef complex<__promote_t<_Tp, _Up> > result_type;
11071107
return std::pow(result_type(__x), result_type(__y));
11081108
}
11091109

11101110
template <class _Tp, class _Up, __enable_if_t<is_floating_point<_Tp>::value && is_arithmetic<_Up>::value, int> = 0>
1111-
inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type> pow(const complex<_Tp>& __x, const _Up& __y) {
1112-
typedef complex<typename __promote<_Tp, _Up>::type> result_type;
1111+
inline _LIBCPP_HIDE_FROM_ABI complex<__promote_t<_Tp, _Up> > pow(const complex<_Tp>& __x, const _Up& __y) {
1112+
typedef complex<__promote_t<_Tp, _Up> > result_type;
11131113
return std::pow(result_type(__x), result_type(__y));
11141114
}
11151115

11161116
template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Tp>::value && is_floating_point<_Up>::value, int> = 0>
1117-
inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type> pow(const _Tp& __x, const complex<_Up>& __y) {
1118-
typedef complex<typename __promote<_Tp, _Up>::type> result_type;
1117+
inline _LIBCPP_HIDE_FROM_ABI complex<__promote_t<_Tp, _Up> > pow(const _Tp& __x, const complex<_Up>& __y) {
1118+
typedef complex<__promote_t<_Tp, _Up> > result_type;
11191119
return std::pow(result_type(__x), result_type(__y));
11201120
}
11211121

libcxx/test/libcxx/numerics/complex.number/cmplx.over.pow.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
1212

13-
// template<class T, class U> complex<__promote<T, U>::type> pow(const complex<T>&, const U&);
14-
// template<class T, class U> complex<__promote<T, U>::type> pow(const complex<T>&, const complex<U>&);
15-
// template<class T, class U> complex<__promote<T, U>::type> pow(const T&, const complex<U>&);
13+
// template<class T, class U> complex<__promote_t<T, U>> pow(const complex<T>&, const U&);
14+
// template<class T, class U> complex<__promote_t<T, U>> pow(const complex<T>&, const complex<U>&);
15+
// template<class T, class U> complex<__promote_t<T, U>> pow(const T&, const complex<U>&);
1616

1717
// Test that these additional overloads are free from catching std::complex<non-floating-point>,
1818
// which is expected by several 3rd party libraries, see https://github.com/llvm/llvm-project/issues/109858.

0 commit comments

Comments
 (0)