|
7 | 7 |
|
8 | 8 | namespace std
|
9 | 9 | {
|
10 |
| - template <class T> |
11 |
| - std::complex<T> operator+(std::complex<T> self, long other) |
| 10 | + template <class T, class S> |
| 11 | + complex_broadcast_t<T, S> operator+(std::complex<T> self, S other) |
12 | 12 | {
|
13 |
| - return self + T(other); |
| 13 | + return (complex_broadcast_t<T, S>)self + |
| 14 | + (typename std::common_type<T, S>::type)(other); |
14 | 15 | }
|
15 | 16 |
|
16 |
| - template <class T> |
17 |
| - std::complex<T> operator+(long self, std::complex<T> other) |
| 17 | + template <class T, class S> |
| 18 | + complex_broadcast_t<T, S> operator+(S self, std::complex<T> other) |
18 | 19 | {
|
19 |
| - return T(self) + other; |
| 20 | + return (typename std::common_type<T, S>::type)(self) + |
| 21 | + (complex_broadcast_t<T, S>)other; |
20 | 22 | }
|
21 | 23 |
|
22 |
| - template <class T> |
23 |
| - std::complex<T> operator-(std::complex<T> self, long other) |
| 24 | + template <class T, class S> |
| 25 | + complex_broadcast_t<T, S> operator-(std::complex<T> self, S other) |
24 | 26 | {
|
25 |
| - return self - T(other); |
| 27 | + return (complex_broadcast_t<T, S>)self - |
| 28 | + (typename std::common_type<T, S>::type)(other); |
26 | 29 | }
|
27 | 30 |
|
28 |
| - template <class T> |
29 |
| - std::complex<T> operator-(long self, std::complex<T> other) |
| 31 | + template <class T, class S> |
| 32 | + complex_broadcast_t<T, S> operator-(S self, std::complex<T> other) |
30 | 33 | {
|
31 |
| - return T(self) - other; |
| 34 | + return (typename std::common_type<T, S>::type)(self) - |
| 35 | + (complex_broadcast_t<T, S>)other; |
32 | 36 | }
|
33 | 37 |
|
34 |
| - template <class T> |
35 |
| - std::complex<T> operator*(std::complex<T> self, long other) |
| 38 | + template <class T, class S> |
| 39 | + complex_broadcast_t<T, S> operator*(std::complex<T> self, S other) |
36 | 40 | {
|
37 |
| - return self * T(other); |
| 41 | + return (complex_broadcast_t<T, S>)self * |
| 42 | + (typename std::common_type<T, S>::type)(other); |
38 | 43 | }
|
39 | 44 |
|
40 |
| - template <class T> |
41 |
| - std::complex<T> operator*(long self, std::complex<T> other) |
| 45 | + template <class T, class S> |
| 46 | + complex_broadcast_t<T, S> operator*(S self, std::complex<T> other) |
42 | 47 | {
|
43 |
| - return T(self) * other; |
| 48 | + return (typename std::common_type<T, S>::type)(self) * |
| 49 | + (complex_broadcast_t<T, S>)other; |
44 | 50 | }
|
45 | 51 |
|
46 |
| - template <class T> |
47 |
| - std::complex<T> operator/(std::complex<T> self, long other) |
| 52 | + template <class T, class S> |
| 53 | + complex_broadcast_t<T, S> operator/(std::complex<T> self, S other) |
48 | 54 | {
|
49 |
| - return self / T(other); |
| 55 | + return (complex_broadcast_t<T, S>)self / |
| 56 | + (typename std::common_type<T, S>::type)(other); |
50 | 57 | }
|
51 | 58 |
|
52 |
| - template <class T> |
53 |
| - std::complex<T> operator/(long self, std::complex<T> other) |
| 59 | + template <class T, class S> |
| 60 | + complex_broadcast_t<T, S> operator/(S self, std::complex<T> other) |
54 | 61 | {
|
55 |
| - return T(self) / other; |
| 62 | + return (typename std::common_type<T, S>::type)(self) / |
| 63 | + (complex_broadcast_t<T, S>)other; |
56 | 64 | }
|
57 | 65 |
|
58 |
| - template <class T> |
59 |
| - bool operator==(std::complex<T> self, long other) |
| 66 | + template <class T, class S> |
| 67 | + complex_bool_t<T, S> operator==(std::complex<T> self, S other) |
60 | 68 | {
|
61 | 69 | return self == T(other);
|
62 | 70 | }
|
63 | 71 |
|
64 |
| - template <class T> |
65 |
| - bool operator==(long self, std::complex<T> other) |
| 72 | + template <class T, class S> |
| 73 | + complex_bool_t<T, S> operator==(S self, std::complex<T> other) |
66 | 74 | {
|
67 | 75 | return T(self) == other;
|
68 | 76 | }
|
69 | 77 |
|
70 |
| - template <class T> |
71 |
| - bool operator!=(std::complex<T> self, long other) |
| 78 | + template <class T, class S> |
| 79 | + complex_bool_t<T, S> operator!=(std::complex<T> self, S other) |
72 | 80 | {
|
73 | 81 | return self != T(other);
|
74 | 82 | }
|
75 | 83 |
|
76 |
| - template <class T> |
77 |
| - bool operator!=(long self, std::complex<T> other) |
| 84 | + template <class T, class S> |
| 85 | + complex_bool_t<T, S> operator!=(S self, std::complex<T> other) |
78 | 86 | {
|
79 | 87 | return T(self) != other;
|
80 | 88 | }
|
81 | 89 |
|
82 |
| - template <class T> |
83 |
| - bool operator<(std::complex<T> self, std::complex<T> other) |
| 90 | + template <class T, class S> |
| 91 | + bool operator<(std::complex<T> self, std::complex<S> other) |
84 | 92 | {
|
85 | 93 | return self.real() == other.real() ? self.imag() < other.imag()
|
86 | 94 | : self.real() < other.real();
|
87 | 95 | }
|
88 | 96 |
|
89 |
| - template <class T> |
90 |
| - bool operator<=(std::complex<T> self, std::complex<T> other) |
| 97 | + template <class T, class S> |
| 98 | + bool operator<=(std::complex<T> self, std::complex<S> other) |
91 | 99 | {
|
92 | 100 | return self.real() == other.real() ? self.imag() <= other.imag()
|
93 | 101 | : self.real() <= other.real();
|
94 | 102 | }
|
95 | 103 |
|
96 |
| - template <class T> |
97 |
| - bool operator>(std::complex<T> self, std::complex<T> other) |
| 104 | + template <class T, class S> |
| 105 | + bool operator>(std::complex<T> self, std::complex<S> other) |
98 | 106 | {
|
99 | 107 | return self.real() == other.real() ? self.imag() > other.imag()
|
100 | 108 | : self.real() > other.real();
|
101 | 109 | }
|
102 | 110 |
|
103 |
| - template <class T> |
104 |
| - bool operator>=(std::complex<T> self, std::complex<T> other) |
| 111 | + template <class T, class S> |
| 112 | + bool operator>=(std::complex<T> self, std::complex<S> other) |
105 | 113 | {
|
106 | 114 | return self.real() == other.real() ? self.imag() >= other.imag()
|
107 | 115 | : self.real() >= other.real();
|
108 | 116 | }
|
109 | 117 |
|
110 |
| - template <class T> |
111 |
| - bool operator&&(std::complex<T> self, std::complex<T> other) |
| 118 | + template <class T, class S> |
| 119 | + bool operator&&(std::complex<T> self, std::complex<S> other) |
112 | 120 | {
|
113 | 121 | return (self.real() || self.imag()) && (other.real() || other.imag());
|
114 | 122 | }
|
115 | 123 |
|
116 |
| - template <class T> |
117 |
| - bool operator||(std::complex<T> self, std::complex<T> other) |
| 124 | + template <class T, class S> |
| 125 | + bool operator||(std::complex<T> self, std::complex<S> other) |
118 | 126 | {
|
119 | 127 | return (self.real() || self.imag()) || (other.real() || other.imag());
|
120 | 128 | }
|
|
0 commit comments