blob: a395f6d6bdd9b19f02976aaeb3b244ff4ed9793f [file] [log] [blame]
Andrew Top61a84952019-04-30 15:07:33 -07001//===----------------------------------------------------------------------===//
2//
Kaido Kert788710a2023-06-05 07:50:22 -07003// 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
Andrew Top61a84952019-04-30 15:07:33 -07006//
7//===----------------------------------------------------------------------===//
8
9// <complex>
10
11// template<class T> complex<T> proj(const complex<T>&);
12// complex<long double> proj(long double);
13// complex<double> proj(double);
14// template<Integral T> complex<double> proj(T);
15// complex<float> proj(float);
16
17#include <complex>
18#include <type_traits>
19#include <cassert>
20
Kaido Kert788710a2023-06-05 07:50:22 -070021#include "test_macros.h"
Andrew Top61a84952019-04-30 15:07:33 -070022#include "../cases.h"
23
24template <class T>
25void
26test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
27{
28 static_assert((std::is_same<decltype(std::proj(x)), std::complex<double> >::value), "");
29 assert(std::proj(x) == proj(std::complex<double>(x, 0)));
30}
31
32template <class T>
33void
34test(T x, typename std::enable_if<std::is_floating_point<T>::value>::type* = 0)
35{
36 static_assert((std::is_same<decltype(std::proj(x)), std::complex<T> >::value), "");
37 assert(std::proj(x) == proj(std::complex<T>(x, 0)));
38}
39
40template <class T>
41void
42test(T x, typename std::enable_if<!std::is_integral<T>::value &&
43 !std::is_floating_point<T>::value>::type* = 0)
44{
45 static_assert((std::is_same<decltype(std::proj(x)), std::complex<T> >::value), "");
46 assert(std::proj(x) == proj(std::complex<T>(x, 0)));
47}
48
49template <class T>
50void
51test()
52{
53 test<T>(0);
54 test<T>(1);
55 test<T>(10);
56}
57
Kaido Kert788710a2023-06-05 07:50:22 -070058int main(int, char**)
Andrew Top61a84952019-04-30 15:07:33 -070059{
60 test<float>();
61 test<double>();
62 test<long double>();
63 test<int>();
64 test<unsigned>();
65 test<long long>();
Kaido Kert788710a2023-06-05 07:50:22 -070066
67 return 0;
Andrew Top61a84952019-04-30 15:07:33 -070068}