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>
13 // T
14 // imag(const T& x);
15
16 #include <complex>
17 #include <type_traits>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "../cases.h"
22
23 template <class T, int x>
24 void
test(typename std::enable_if<std::is_integral<T>::value>::type * =0)25 test(typename std::enable_if<std::is_integral<T>::value>::type* = 0)
26 {
27 static_assert((std::is_same<decltype(std::imag(T(x))), double>::value), "");
28 assert(std::imag(x) == 0);
29 #if TEST_STD_VER > 11
30 constexpr T val {x};
31 static_assert(std::imag(val) == 0, "");
32 constexpr std::complex<T> t{val, val};
33 static_assert(t.imag() == x, "" );
34 #endif
35 }
36
37 template <class T, int x>
38 void
test(typename std::enable_if<!std::is_integral<T>::value>::type * =0)39 test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
40 {
41 static_assert((std::is_same<decltype(std::imag(T(x))), T>::value), "");
42 assert(std::imag(x) == 0);
43 #if TEST_STD_VER > 11
44 constexpr T val {x};
45 static_assert(std::imag(val) == 0, "");
46 constexpr std::complex<T> t{val, val};
47 static_assert(t.imag() == x, "" );
48 #endif
49 }
50
51 template <class T>
52 void
test()53 test()
54 {
55 test<T, 0>();
56 test<T, 1>();
57 test<T, 10>();
58 }
59
main()60 int main()
61 {
62 test<float>();
63 test<double>();
64 test<long double>();
65 test<int>();
66 test<unsigned>();
67 test<long long>();
68 }
69