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// complex& operator=(const complex&);
12// template<class X> complex& operator= (const complex<X>&); // constexpr in C++20
13
14#include <complex>
15#include <cassert>
16
17#include "test_macros.h"
18
19template <class T, class X>
20TEST_CONSTEXPR_CXX20
21bool
22test()
23{
24 std::complex<T> c;
25 assert(c.real() == 0);
26 assert(c.imag() == 0);
27 std::complex<T> c2(1.5, 2.5);
28 c = c2;
29 assert(c.real() == 1.5);
30 assert(c.imag() == 2.5);
31 std::complex<X> c3(3.5, -4.5);
32 c = c3;
33 assert(c.real() == 3.5);
34 assert(c.imag() == -4.5);
35 return true;
36}
37
38int main(int, char**)
39{
40 test<float, float>();
41 test<float, double>();
42 test<float, long double>();
43
44 test<double, float>();
45 test<double, double>();
46 test<double, long double>();
47
48 test<long double, float>();
49 test<long double, double>();
50 test<long double, long double>();
51
52#if TEST_STD_VER >= 20
53 static_assert(test<float, float>());
54 static_assert(test<float, double>());
55 static_assert(test<float, long double>());
56
57 static_assert(test<double, float>());
58 static_assert(test<double, double>());
59 static_assert(test<double, long double>());
60
61 static_assert(test<long double, float>());
62 static_assert(test<long double, double>());
63 static_assert(test<long double, long double>());
64#endif
65
66 return 0;
67}
68

source code of libcxx/test/std/numerics/complex.number/complex.member.ops/assignment_complex.pass.cpp