70 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <complex>10 11// template<Arithmetic T>12// T13// imag(const T& x);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, int x>23void24test(typename std::enable_if<std::is_integral<T>::value>::type* = 0)25{26 static_assert((std::is_same<decltype(std::imag(T(x))), double>::value), "");27 assert(std::imag(x) == 0);28#if TEST_STD_VER > 1129 constexpr T val {x};30 static_assert(std::imag(val) == 0, "");31 constexpr std::complex<T> t{val, val};32 static_assert(t.imag() == x, "" );33#endif34}35 36template <class T, int x>37void38test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0)39{40 static_assert((std::is_same<decltype(std::imag(T(x))), T>::value), "");41 assert(std::imag(x) == 0);42#if TEST_STD_VER > 1143 constexpr T val {x};44 static_assert(std::imag(val) == 0, "");45 constexpr std::complex<T> t{val, val};46 static_assert(t.imag() == x, "" );47#endif48}49 50template <class T>51void52test()53{54 test<T, 0>();55 test<T, 1>();56 test<T, 10>();57}58 59int main(int, char**)60{61 test<float>();62 test<double>();63 test<long double>();64 test<int>();65 test<unsigned>();66 test<long long>();67 68 return 0;69}70