Home | History | Annotate | Download | only in complex.members
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <complex>
     11 
     12 // constexpr complex(const T& re = T(), const T& im = T());
     13 
     14 #include <complex>
     15 #include <cassert>
     16 
     17 #include "test_macros.h"
     18 
     19 template <class T>
     20 void
     21 test()
     22 {
     23     {
     24     const std::complex<T> c;
     25     assert(c.real() == 0);
     26     assert(c.imag() == 0);
     27     }
     28     {
     29     const std::complex<T> c = 7.5;
     30     assert(c.real() == 7.5);
     31     assert(c.imag() == 0);
     32     }
     33     {
     34     const std::complex<T> c(8.5);
     35     assert(c.real() == 8.5);
     36     assert(c.imag() == 0);
     37     }
     38     {
     39     const std::complex<T> c(10.5, -9.5);
     40     assert(c.real() == 10.5);
     41     assert(c.imag() == -9.5);
     42     }
     43 #if TEST_STD_VER >= 11
     44     {
     45     constexpr std::complex<T> c;
     46     static_assert(c.real() == 0, "");
     47     static_assert(c.imag() == 0, "");
     48     }
     49     {
     50     constexpr std::complex<T> c = 7.5;
     51     static_assert(c.real() == 7.5, "");
     52     static_assert(c.imag() == 0, "");
     53     }
     54     {
     55     constexpr std::complex<T> c(8.5);
     56     static_assert(c.real() == 8.5, "");
     57     static_assert(c.imag() == 0, "");
     58     }
     59     {
     60     constexpr std::complex<T> c(10.5, -9.5);
     61     static_assert(c.real() == 10.5, "");
     62     static_assert(c.imag() == -9.5, "");
     63     }
     64 #endif
     65 }
     66 
     67 int main()
     68 {
     69     test<float>();
     70     test<double>();
     71     test<long double>();
     72 }
     73