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