constexpr applied to <complex>.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@160585 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant
2012-07-20 22:18:27 +00:00
parent c83960a9e4
commit 410f2def47
11 changed files with 134 additions and 22 deletions

View File

@@ -9,7 +9,7 @@
// <complex>
// complex(const T& re = T(), const T& im = T());
// constexpr complex(const T& re = T(), const T& im = T());
#include <complex>
#include <cassert>
@@ -38,6 +38,28 @@ test()
assert(c.real() == 10.5);
assert(c.imag() == -9.5);
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<T> c;
static_assert(c.real() == 0, "");
static_assert(c.imag() == 0, "");
}
{
constexpr std::complex<T> c = 7.5;
static_assert(c.real() == 7.5, "");
static_assert(c.imag() == 0, "");
}
{
constexpr std::complex<T> c(8.5);
static_assert(c.real() == 8.5, "");
static_assert(c.imag() == 0, "");
}
{
constexpr std::complex<T> c(10.5, -9.5);
static_assert(c.real() == 10.5, "");
static_assert(c.imag() == -9.5, "");
}
#endif
}
int main()

View File

@@ -20,8 +20,18 @@
int main()
{
{
const std::complex<float> cd(2.5, 3.5);
std::complex<double> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<float> cd(2.5, 3.5);
constexpr std::complex<double> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -20,8 +20,18 @@
int main()
{
{
const std::complex<float> cd(2.5, 3.5);
std::complex<double> cf = cd;
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<float> cd(2.5, 3.5);
constexpr std::complex<double> cf = cd;
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -20,8 +20,18 @@
int main()
{
{
const std::complex<long double> cd(2.5, 3.5);
std::complex<double> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<long double> cd(2.5, 3.5);
constexpr std::complex<double> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -20,8 +20,18 @@
int main()
{
{
const std::complex<double> cd(2.5, 3.5);
std::complex<float> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<double> cd(2.5, 3.5);
constexpr std::complex<float> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -20,8 +20,18 @@
int main()
{
{
const std::complex<long double> cd(2.5, 3.5);
std::complex<float> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<long double> cd(2.5, 3.5);
constexpr std::complex<float> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -20,8 +20,18 @@
int main()
{
{
const std::complex<double> cd(2.5, 3.5);
std::complex<long double> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<double> cd(2.5, 3.5);
constexpr std::complex<long double> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -20,8 +20,18 @@
int main()
{
{
const std::complex<double> cd(2.5, 3.5);
std::complex<long double> cf = cd;
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<double> cd(2.5, 3.5);
constexpr std::complex<long double> cf = cd;
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -20,8 +20,18 @@
int main()
{
{
const std::complex<float> cd(2.5, 3.5);
std::complex<long double> cf(cd);
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<float> cd(2.5, 3.5);
constexpr std::complex<long double> cf(cd);
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}

View File

@@ -20,8 +20,18 @@
int main()
{
{
const std::complex<float> cd(2.5, 3.5);
std::complex<long double> cf = cd;
assert(cf.real() == cd.real());
assert(cf.imag() == cd.imag());
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::complex<float> cd(2.5, 3.5);
constexpr std::complex<long double> cf = cd;
static_assert(cf.real() == cd.real(), "");
static_assert(cf.imag() == cd.imag(), "");
}
#endif
}