Skip to content

Commit 051c836

Browse files
committed
[libc++][NFC] Simplify the implementation of __promote
1 parent 4d323e4 commit 051c836

File tree

1 file changed

+6
-53
lines changed

1 file changed

+6
-53
lines changed

libcxx/include/__type_traits/promote.h

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
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>
1615

1716
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1817
# pragma GCC system_header
1918
#endif
2019

2120
_LIBCPP_BEGIN_NAMESPACE_STD
2221

23-
template <class _Tp>
24-
struct __numeric_type {
25-
static void __test(...);
22+
template <class... _Args>
23+
class __promote {
24+
static_assert((is_arithmetic<_Args>::value && ...));
25+
2626
static float __test(float);
2727
static double __test(char);
2828
static double __test(int);
@@ -38,57 +38,10 @@ struct __numeric_type {
3838
static double __test(double);
3939
static long double __test(long double);
4040

41-
typedef decltype(__test(std::declval<_Tp>())) type;
42-
static const bool value = _IsNotSame<type, void>::value;
43-
};
44-
45-
template <>
46-
struct __numeric_type<void> {
47-
static const bool value = true;
48-
};
49-
50-
template <class _A1,
51-
class _A2 = void,
52-
class _A3 = void,
53-
bool = __numeric_type<_A1>::value && __numeric_type<_A2>::value && __numeric_type<_A3>::value>
54-
class __promote_imp {
55-
public:
56-
static const bool value = false;
57-
};
58-
59-
template <class _A1, class _A2, class _A3>
60-
class __promote_imp<_A1, _A2, _A3, true> {
61-
private:
62-
typedef typename __promote_imp<_A1>::type __type1;
63-
typedef typename __promote_imp<_A2>::type __type2;
64-
typedef typename __promote_imp<_A3>::type __type3;
65-
6641
public:
67-
typedef decltype(__type1() + __type2() + __type3()) type;
68-
static const bool value = true;
42+
using type = decltype((__test(_Args()) + ...));
6943
};
7044

71-
template <class _A1, class _A2>
72-
class __promote_imp<_A1, _A2, void, true> {
73-
private:
74-
typedef typename __promote_imp<_A1>::type __type1;
75-
typedef typename __promote_imp<_A2>::type __type2;
76-
77-
public:
78-
typedef decltype(__type1() + __type2()) type;
79-
static const bool value = true;
80-
};
81-
82-
template <class _A1>
83-
class __promote_imp<_A1, void, void, true> {
84-
public:
85-
typedef typename __numeric_type<_A1>::type type;
86-
static const bool value = true;
87-
};
88-
89-
template <class _A1, class _A2 = void, class _A3 = void>
90-
class __promote : public __promote_imp<_A1, _A2, _A3> {};
91-
9245
_LIBCPP_END_NAMESPACE_STD
9346

9447
#endif // _LIBCPP___TYPE_TRAITS_PROMOTE_H

0 commit comments

Comments
 (0)