| 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<class T> complex<T> conj(const complex<T>&); // constexpr in C++20 |
| 12 | // complex<long double> conj(long double); // constexpr in C++20 |
| 13 | // complex<double> conj(double); // constexpr in C++20 |
| 14 | // template<Integral T> complex<double> conj(T); // constexpr in C++20 |
| 15 | // complex<float> conj(float); // constexpr in C++20 |
| 16 | |
| 17 | #include <complex> |
| 18 | #include <type_traits> |
| 19 | #include <cassert> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | #include "../cases.h" |
| 23 | |
| 24 | template <class T> |
| 25 | TEST_CONSTEXPR_CXX20 |
| 26 | void |
| 27 | test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0) |
| 28 | { |
| 29 | static_assert((std::is_same<decltype(std::conj(x)), std::complex<double> >::value), "" ); |
| 30 | assert(std::conj(x) == conj(std::complex<double>(x, 0))); |
| 31 | } |
| 32 | |
| 33 | template <class T> |
| 34 | TEST_CONSTEXPR_CXX20 |
| 35 | void |
| 36 | test(T x, typename std::enable_if<std::is_floating_point<T>::value>::type* = 0) |
| 37 | { |
| 38 | static_assert((std::is_same<decltype(std::conj(x)), std::complex<T> >::value), "" ); |
| 39 | assert(std::conj(x) == conj(std::complex<T>(x, 0))); |
| 40 | } |
| 41 | |
| 42 | template <class T> |
| 43 | TEST_CONSTEXPR_CXX20 |
| 44 | void |
| 45 | test(T x, typename std::enable_if<!std::is_integral<T>::value && |
| 46 | !std::is_floating_point<T>::value>::type* = 0) |
| 47 | { |
| 48 | static_assert((std::is_same<decltype(std::conj(x)), std::complex<T> >::value), "" ); |
| 49 | assert(std::conj(x) == conj(std::complex<T>(x, 0))); |
| 50 | } |
| 51 | |
| 52 | template <class T> |
| 53 | TEST_CONSTEXPR_CXX20 |
| 54 | bool |
| 55 | test() |
| 56 | { |
| 57 | test<T>(0); |
| 58 | test<T>(1); |
| 59 | test<T>(10); |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | int main(int, char**) |
| 64 | { |
| 65 | test<float>(); |
| 66 | test<double>(); |
| 67 | test<long double>(); |
| 68 | test<int>(); |
| 69 | test<unsigned>(); |
| 70 | test<long long>(); |
| 71 | |
| 72 | #if TEST_STD_VER >= 20 |
| 73 | static_assert(test<float>()); |
| 74 | static_assert(test<double>()); |
| 75 | static_assert(test<long double>()); |
| 76 | static_assert(test<int>()); |
| 77 | static_assert(test<unsigned>()); |
| 78 | static_assert(test<long long>()); |
| 79 | #endif |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |