| 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 |
// constexpr complex(const T& re = T(), const T& im = T()); |
| 12 |
|
| 13 |
#include <complex> |
| 14 |
#include <cassert> |
| 15 |
|
| 16 |
#include "test_macros.h" |
| 17 |
|
| 18 |
template <class T> |
| 19 |
void |
| 20 |
test() |
| 21 |
{ |
| 22 |
{ |
| 23 |
const std::complex<T> c; |
| 24 |
assert(c.real() == 0); |
| 25 |
assert(c.imag() == 0); |
| 26 |
} |
| 27 |
{ |
| 28 |
const std::complex<T> c = 7.5; |
| 29 |
assert(c.real() == 7.5); |
| 30 |
assert(c.imag() == 0); |
| 31 |
} |
| 32 |
{ |
| 33 |
const std::complex<T> c(8.5); |
| 34 |
assert(c.real() == 8.5); |
| 35 |
assert(c.imag() == 0); |
| 36 |
} |
| 37 |
{ |
| 38 |
const std::complex<T> c(10.5, -9.5); |
| 39 |
assert(c.real() == 10.5); |
| 40 |
assert(c.imag() == -9.5); |
| 41 |
} |
| 42 |
#if TEST_STD_VER >= 11 |
| 43 |
{ |
| 44 |
constexpr std::complex<T> c; |
| 45 |
static_assert(c.real() == 0, ""); |
| 46 |
static_assert(c.imag() == 0, ""); |
| 47 |
} |
| 48 |
{ |
| 49 |
constexpr std::complex<T> c = 7.5; |
| 50 |
static_assert(c.real() == 7.5, ""); |
| 51 |
static_assert(c.imag() == 0, ""); |
| 52 |
} |
| 53 |
{ |
| 54 |
constexpr std::complex<T> c(8.5); |
| 55 |
static_assert(c.real() == 8.5, ""); |
| 56 |
static_assert(c.imag() == 0, ""); |
| 57 |
} |
| 58 |
{ |
| 59 |
constexpr std::complex<T> c(10.5, -9.5); |
| 60 |
static_assert(c.real() == 10.5, ""); |
| 61 |
static_assert(c.imag() == -9.5, ""); |
| 62 |
} |
| 63 |
#endif |
| 64 |
} |
| 65 |
|
| 66 |
int main(int, char**) |
| 67 |
{ |
| 68 |
test<float>(); |
| 69 |
test<double>(); |
| 70 |
test<long double>(); |
| 71 |
|
| 72 |
return 0; |
| 73 |
} |