| 1 | #ifndef _LIBCPP_VERSION |
| 2 | #error "for libc++ only" |
| 3 | #endif |
| 4 | |
| 5 | namespace libcxx_fix { |
| 6 | |
| 7 | using std::is_integral; |
| 8 | using std::is_same; |
| 9 | using std::enable_if; |
| 10 | |
| 11 | template <class _Tp, class _Tn = void> |
| 12 | struct numeric_type |
| 13 | { |
| 14 | typedef void type; |
| 15 | static const bool value = false; |
| 16 | }; |
| 17 | |
| 18 | template <class _Tp> |
| 19 | struct numeric_type<_Tp, typename enable_if<is_integral<_Tp>::value || |
| 20 | is_same<_Tp, double>::value>::type> |
| 21 | { |
| 22 | typedef double type; |
| 23 | static const bool value = true; |
| 24 | }; |
| 25 | |
| 26 | template <class _Tp> |
| 27 | struct numeric_type<_Tp, typename enable_if<is_same<_Tp, long double>::value || |
| 28 | is_same<_Tp, float>::value>::type> |
| 29 | { |
| 30 | typedef _Tp type; |
| 31 | static const bool value = true; |
| 32 | }; |
| 33 | |
| 34 | template <> |
| 35 | struct numeric_type<void, void> |
| 36 | { |
| 37 | static const bool value = true; |
| 38 | }; |
| 39 | |
| 40 | template <class _A1, class _A2, |
| 41 | bool = numeric_type<_A1>::value && |
| 42 | numeric_type<_A2>::value> |
| 43 | class promote |
| 44 | {}; |
| 45 | |
| 46 | template <class _A1, class _A2> |
| 47 | class promote<_A1, _A2, true> |
| 48 | { |
| 49 | private: |
| 50 | typedef typename numeric_type<_A1>::type __type1; |
| 51 | typedef typename numeric_type<_A2>::type __type2; |
| 52 | public: |
| 53 | typedef decltype(__type1() + __type2()) type; |
| 54 | }; |
| 55 | |
| 56 | template <class _A1, class _A2> |
| 57 | inline _LIBCPP_INLINE_VISIBILITY |
| 58 | typename promote<_A1, _A2>::type |
| 59 | pow(_A1 __x, _A2 __y) _NOEXCEPT |
| 60 | { |
| 61 | typedef typename promote<_A1, _A2>::type __result_type; |
| 62 | #if _LIBCPP_STD_VER > 11 |
| 63 | static_assert((!(is_same<_A1, __result_type>::value && |
| 64 | is_same<_A2, __result_type>::value)), ""); |
| 65 | #endif |
| 66 | return ::pow(static_cast<__result_type>(__x), static_cast<__result_type>(__y)); |
| 67 | } |
| 68 | |
| 69 | } |