brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 26db8dd Raw
76 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// void real(T val); // constexpr in C++2012// void imag(T val); // constexpr in C++2013 14#include <complex>15#include <cassert>16 17#include "test_macros.h"18 19template <class T>20TEST_CONSTEXPR_CXX2021void22test_constexpr()23{24#if TEST_STD_VER > 1125    constexpr std::complex<T> c1;26    static_assert(c1.real() == 0, "");27    static_assert(c1.imag() == 0, "");28    constexpr std::complex<T> c2(3);29    static_assert(c2.real() == 3, "");30    static_assert(c2.imag() == 0, "");31    constexpr std::complex<T> c3(3, 4);32    static_assert(c3.real() == 3, "");33    static_assert(c3.imag() == 4, "");34#endif35}36 37template <class T>38TEST_CONSTEXPR_CXX2039bool40test()41{42    std::complex<T> c;43    assert(c.real() == 0);44    assert(c.imag() == 0);45    c.real(3.5);46    assert(c.real() == 3.5);47    assert(c.imag() == 0);48    c.imag(4.5);49    assert(c.real() == 3.5);50    assert(c.imag() == 4.5);51    c.real(-4.5);52    assert(c.real() == -4.5);53    assert(c.imag() == 4.5);54    c.imag(-5.5);55    assert(c.real() == -4.5);56    assert(c.imag() == -5.5);57 58    test_constexpr<T>();59    return true;60}61 62int main(int, char**) {63    test<float>();64    test<double>();65    test<long double>();66    test_constexpr<int>();67 68#if TEST_STD_VER >= 2069    static_assert(test<float>());70    static_assert(test<double>());71    static_assert(test<long double>());72#endif73 74  return 0;75}76