1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <complex>
11 
12 // template<Arithmetic T, Arithmetic U>
13 //   complex<promote<T, U>::type>
14 //   pow(const T& x, const complex<U>& y);
15 
16 // template<Arithmetic T, Arithmetic U>
17 //   complex<promote<T, U>::type>
18 //   pow(const complex<T>& x, const U& y);
19 
20 // template<Arithmetic T, Arithmetic U>
21 //   complex<promote<T, U>::type>
22 //   pow(const complex<T>& x, const complex<U>& y);
23 
24 #include <complex>
25 #include <type_traits>
26 #include <cassert>
27 
28 #include "../cases.h"
29 
30 template <class T>
31 double
32 promote(T, typename std::enable_if<std::is_integral<T>::value>::type* = 0);
33 
34 float promote(float);
35 double promote(double);
36 long double promote(long double);
37 
38 template <class T, class U>
39 void
test(T x,const std::complex<U> & y)40 test(T x, const std::complex<U>& y)
41 {
42     typedef decltype(promote(x)+promote(real(y))) V;
43     static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), "");
44     assert(std::pow(x, y) == pow(std::complex<V>(x, 0), std::complex<V>(y)));
45 }
46 
47 template <class T, class U>
48 void
test(const std::complex<T> & x,U y)49 test(const std::complex<T>& x, U y)
50 {
51     typedef decltype(promote(real(x))+promote(y)) V;
52     static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), "");
53     assert(std::pow(x, y) == pow(std::complex<V>(x), std::complex<V>(y, 0)));
54 }
55 
56 template <class T, class U>
57 void
test(const std::complex<T> & x,const std::complex<U> & y)58 test(const std::complex<T>& x, const std::complex<U>& y)
59 {
60     typedef decltype(promote(real(x))+promote(real(y))) V;
61     static_assert((std::is_same<decltype(std::pow(x, y)), std::complex<V> >::value), "");
62     assert(std::pow(x, y) == pow(std::complex<V>(x), std::complex<V>(y)));
63 }
64 
65 template <class T, class U>
66 void
test(typename std::enable_if<std::is_integral<T>::value>::type * =0,typename std::enable_if<!std::is_integral<U>::value>::type * =0)67 test(typename std::enable_if<std::is_integral<T>::value>::type* = 0, typename std::enable_if<!std::is_integral<U>::value>::type* = 0)
68 {
69     test(T(3), std::complex<U>(4, 5));
70     test(std::complex<U>(3, 4), T(5));
71 }
72 
73 template <class T, class U>
74 void
test(typename std::enable_if<!std::is_integral<T>::value>::type * =0,typename std::enable_if<!std::is_integral<U>::value>::type * =0)75 test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0, typename std::enable_if<!std::is_integral<U>::value>::type* = 0)
76 {
77     test(T(3), std::complex<U>(4, 5));
78     test(std::complex<T>(3, 4), U(5));
79     test(std::complex<T>(3, 4), std::complex<U>(5, 6));
80 }
81 
main()82 int main()
83 {
84     test<int, float>();
85     test<int, double>();
86     test<int, long double>();
87 
88     test<unsigned, float>();
89     test<unsigned, double>();
90     test<unsigned, long double>();
91 
92     test<long long, float>();
93     test<long long, double>();
94     test<long long, long double>();
95 
96     test<float, double>();
97     test<float, long double>();
98 
99     test<double, float>();
100     test<double, long double>();
101 
102     test<long double, float>();
103     test<long double, double>();
104 }
105