-
Notifications
You must be signed in to change notification settings - Fork 0
/
complex_number.hpp
28 lines (25 loc) · 1.23 KB
/
complex_number.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef COMPLEX_NUMBER_HPP_
#define COMPLEX_NUMBER_HPP_
// Trick to allow type promotion below
template <typename T>
struct identity_t { typedef T type; };
/// Make working with std::complex<> nubmers suck less... allow promotion.
#define COMPLEX_OPS(OP) \
template <typename _Tp> \
std::complex<_Tp> \
operator OP(std::complex<_Tp> lhs, const typename identity_t<_Tp>::type & rhs) \
{ \
return lhs OP rhs; \
} \
template <typename _Tp> \
std::complex<_Tp> \
operator OP(const typename identity_t<_Tp>::type & lhs, const std::complex<_Tp> & rhs) \
{ \
return lhs OP rhs; \
}
COMPLEX_OPS(+)
COMPLEX_OPS(-)
COMPLEX_OPS(*)
COMPLEX_OPS(/)
#undef COMPLEX_OPS
#endif /* COMPLEX_NUMBER_HPP_ */