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