1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <complex>
10
11// template<Arithmetic T>
12// T
13// norm(T x); // constexpr in C++20
14
15#include <complex>
16#include <type_traits>
17#include <cassert>
18
19#include "test_macros.h"
20#include "../cases.h"
21
22template <class T>
23TEST_CONSTEXPR_CXX20
24void
25test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
26{
27 static_assert((std::is_same<decltype(std::norm(x)), double>::value), "");
28 assert(std::norm(x) == norm(std::complex<double>(static_cast<double>(x), 0)));
29}
30
31template <class T>
32TEST_CONSTEXPR_CXX20
33void
34test(T x, typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
35{
36 static_assert((std::is_same<decltype(std::norm(x)), T>::value), "");
37 assert(std::norm(x) == norm(std::complex<T>(x, 0)));
38}
39
40template <class T>
41TEST_CONSTEXPR_CXX20
42bool
43test()
44{
45 test<T>(0);
46 test<T>(1);
47 test<T>(10);
48 return true;
49}
50
51int main(int, char**)
52{
53 test<float>();
54 test<double>();
55 test<long double>();
56 test<int>();
57 test<unsigned>();
58 test<long long>();
59
60#if TEST_STD_VER >= 20
61 static_assert(test<float>());
62 static_assert(test<double>());
63 static_assert(test<long double>());
64 static_assert(test<int>());
65 static_assert(test<unsigned>());
66 static_assert(test<long long>());
67#endif
68
69 return 0;
70}
71

source code of libcxx/test/std/numerics/complex.number/cmplx.over/norm.pass.cpp