xref: /llvm-project/libcxx/test/std/numerics/complex.number/complex.member.ops/assignment_scalar.pass.cpp (revision 7223bcf04c4ce3c1585df9408c6a6663cc8364ea)
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 T&); // constexpr in C++20
12 
13 #include <complex>
14 #include <cassert>
15 
16 #include "test_macros.h"
17 
18 template <class T>
19 TEST_CONSTEXPR_CXX20
20 bool
test()21 test()
22 {
23     std::complex<T> c;
24     assert(c.real() == 0);
25     assert(c.imag() == 0);
26     c = 1.5;
27     assert(c.real() == 1.5);
28     assert(c.imag() == 0);
29     c = -1.5;
30     assert(c.real() == -1.5);
31     assert(c.imag() == 0);
32     return true;
33 }
34 
main(int,char **)35 int main(int, char**)
36 {
37     test<float>();
38     test<double>();
39     test<long double>();
40 
41 #if TEST_STD_VER >= 20
42     static_assert(test<float>());
43     static_assert(test<double>());
44     static_assert(test<long double>());
45 #endif
46 
47   return 0;
48 }
49