From 410f2def474e25c7997d0b539391f5715e287e65 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 20 Jul 2012 22:18:27 +0000 Subject: [PATCH] constexpr applied to . git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@160585 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/complex | 42 +++++++++---------- .../complex.members/construct.pass.cpp | 24 ++++++++++- .../double_float_explicit.pass.cpp | 10 +++++ .../double_float_implicit.pass.cpp | 10 +++++ .../double_long_double_explicit.pass.cpp | 10 +++++ .../float_double_explicit.pass.cpp | 10 +++++ .../float_long_double_explicit.pass.cpp | 10 +++++ .../long_double_double_explicit.pass.cpp | 10 +++++ .../long_double_double_implicit.pass.cpp | 10 +++++ .../long_double_float_explicit.pass.cpp | 10 +++++ .../long_double_float_implicit.pass.cpp | 10 +++++ 11 files changed, 134 insertions(+), 22 deletions(-) diff --git a/include/complex b/include/complex index 3b660a35..54dbc258 100644 --- a/include/complex +++ b/include/complex @@ -330,13 +330,13 @@ class _LIBCPP_VISIBLE complex public: typedef float value_type; - /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(float __re = 0.0f, float __im = 0.0f) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(float __re = 0.0f, float __im = 0.0f) : __re_(__re), __im_(__im) {} - explicit /*constexpr*/ complex(const complex& __c); - explicit /*constexpr*/ complex(const complex& __c); + explicit _LIBCPP_CONSTEXPR complex(const complex& __c); + explicit _LIBCPP_CONSTEXPR complex(const complex& __c); - /*constexpr*/ _LIBCPP_INLINE_VISIBILITY float real() const {return __re_;} - /*constexpr*/ _LIBCPP_INLINE_VISIBILITY float imag() const {return __im_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float imag() const {return __im_;} _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} @@ -386,13 +386,13 @@ class _LIBCPP_VISIBLE complex public: typedef double value_type; - /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(double __re = 0.0, double __im = 0.0) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(double __re = 0.0, double __im = 0.0) : __re_(__re), __im_(__im) {} - /*constexpr*/ complex(const complex& __c); - explicit /*constexpr*/ complex(const complex& __c); + _LIBCPP_CONSTEXPR complex(const complex& __c); + explicit _LIBCPP_CONSTEXPR complex(const complex& __c); - /*constexpr*/ _LIBCPP_INLINE_VISIBILITY double real() const {return __re_;} - /*constexpr*/ _LIBCPP_INLINE_VISIBILITY double imag() const {return __im_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double imag() const {return __im_;} _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} @@ -442,13 +442,13 @@ class _LIBCPP_VISIBLE complex public: typedef long double value_type; - /*constexpr*/ _LIBCPP_INLINE_VISIBILITY complex(long double __re = 0.0L, long double __im = 0.0L) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(long double __re = 0.0L, long double __im = 0.0L) : __re_(__re), __im_(__im) {} - /*constexpr*/ complex(const complex& __c); - /*constexpr*/ complex(const complex& __c); + _LIBCPP_CONSTEXPR complex(const complex& __c); + _LIBCPP_CONSTEXPR complex(const complex& __c); - /*constexpr*/ _LIBCPP_INLINE_VISIBILITY long double real() const {return __re_;} - /*constexpr*/ _LIBCPP_INLINE_VISIBILITY long double imag() const {return __im_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double real() const {return __re_;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double imag() const {return __im_;} _LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;} _LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;} @@ -490,33 +490,33 @@ public: } }; -//constexpr inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR complex::complex(const complex& __c) : __re_(__c.real()), __im_(__c.imag()) {} -//constexpr inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR complex::complex(const complex& __c) : __re_(__c.real()), __im_(__c.imag()) {} -//constexpr inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR complex::complex(const complex& __c) : __re_(__c.real()), __im_(__c.imag()) {} -//constexpr inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR complex::complex(const complex& __c) : __re_(__c.real()), __im_(__c.imag()) {} -//constexpr inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR complex::complex(const complex& __c) : __re_(__c.real()), __im_(__c.imag()) {} -//constexpr inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR complex::complex(const complex& __c) : __re_(__c.real()), __im_(__c.imag()) {} diff --git a/test/numerics/complex.number/complex.members/construct.pass.cpp b/test/numerics/complex.number/complex.members/construct.pass.cpp index 23374c5e..b4d870fa 100644 --- a/test/numerics/complex.number/complex.members/construct.pass.cpp +++ b/test/numerics/complex.number/complex.members/construct.pass.cpp @@ -9,7 +9,7 @@ // -// complex(const T& re = T(), const T& im = T()); +// constexpr complex(const T& re = T(), const T& im = T()); #include #include @@ -38,6 +38,28 @@ test() assert(c.real() == 10.5); assert(c.imag() == -9.5); } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex c; + static_assert(c.real() == 0, ""); + static_assert(c.imag() == 0, ""); + } + { + constexpr std::complex c = 7.5; + static_assert(c.real() == 7.5, ""); + static_assert(c.imag() == 0, ""); + } + { + constexpr std::complex c(8.5); + static_assert(c.real() == 8.5, ""); + static_assert(c.imag() == 0, ""); + } + { + constexpr std::complex c(10.5, -9.5); + static_assert(c.real() == 10.5, ""); + static_assert(c.imag() == -9.5, ""); + } +#endif } int main() diff --git a/test/numerics/complex.number/complex.special/double_float_explicit.pass.cpp b/test/numerics/complex.number/complex.special/double_float_explicit.pass.cpp index 038e1710..e8d07ce2 100644 --- a/test/numerics/complex.number/complex.special/double_float_explicit.pass.cpp +++ b/test/numerics/complex.number/complex.special/double_float_explicit.pass.cpp @@ -20,8 +20,18 @@ int main() { + { const std::complex cd(2.5, 3.5); std::complex cf(cd); assert(cf.real() == cd.real()); assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex cd(2.5, 3.5); + constexpr std::complex cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif } diff --git a/test/numerics/complex.number/complex.special/double_float_implicit.pass.cpp b/test/numerics/complex.number/complex.special/double_float_implicit.pass.cpp index 197c6ceb..298aaa3a 100644 --- a/test/numerics/complex.number/complex.special/double_float_implicit.pass.cpp +++ b/test/numerics/complex.number/complex.special/double_float_implicit.pass.cpp @@ -20,8 +20,18 @@ int main() { + { const std::complex cd(2.5, 3.5); std::complex cf = cd; assert(cf.real() == cd.real()); assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex cd(2.5, 3.5); + constexpr std::complex cf = cd; + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif } diff --git a/test/numerics/complex.number/complex.special/double_long_double_explicit.pass.cpp b/test/numerics/complex.number/complex.special/double_long_double_explicit.pass.cpp index 79c709e9..6ff74a2c 100644 --- a/test/numerics/complex.number/complex.special/double_long_double_explicit.pass.cpp +++ b/test/numerics/complex.number/complex.special/double_long_double_explicit.pass.cpp @@ -20,8 +20,18 @@ int main() { + { const std::complex cd(2.5, 3.5); std::complex cf(cd); assert(cf.real() == cd.real()); assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex cd(2.5, 3.5); + constexpr std::complex cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif } diff --git a/test/numerics/complex.number/complex.special/float_double_explicit.pass.cpp b/test/numerics/complex.number/complex.special/float_double_explicit.pass.cpp index 01002b35..77ca9d7f 100644 --- a/test/numerics/complex.number/complex.special/float_double_explicit.pass.cpp +++ b/test/numerics/complex.number/complex.special/float_double_explicit.pass.cpp @@ -20,8 +20,18 @@ int main() { + { const std::complex cd(2.5, 3.5); std::complex cf(cd); assert(cf.real() == cd.real()); assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex cd(2.5, 3.5); + constexpr std::complex cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif } diff --git a/test/numerics/complex.number/complex.special/float_long_double_explicit.pass.cpp b/test/numerics/complex.number/complex.special/float_long_double_explicit.pass.cpp index 9203fd5a..4fb11b4c 100644 --- a/test/numerics/complex.number/complex.special/float_long_double_explicit.pass.cpp +++ b/test/numerics/complex.number/complex.special/float_long_double_explicit.pass.cpp @@ -20,8 +20,18 @@ int main() { + { const std::complex cd(2.5, 3.5); std::complex cf(cd); assert(cf.real() == cd.real()); assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex cd(2.5, 3.5); + constexpr std::complex cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif } diff --git a/test/numerics/complex.number/complex.special/long_double_double_explicit.pass.cpp b/test/numerics/complex.number/complex.special/long_double_double_explicit.pass.cpp index b604fd4b..dd10c808 100644 --- a/test/numerics/complex.number/complex.special/long_double_double_explicit.pass.cpp +++ b/test/numerics/complex.number/complex.special/long_double_double_explicit.pass.cpp @@ -20,8 +20,18 @@ int main() { + { const std::complex cd(2.5, 3.5); std::complex cf(cd); assert(cf.real() == cd.real()); assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex cd(2.5, 3.5); + constexpr std::complex cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif } diff --git a/test/numerics/complex.number/complex.special/long_double_double_implicit.pass.cpp b/test/numerics/complex.number/complex.special/long_double_double_implicit.pass.cpp index 14eff25e..aab53940 100644 --- a/test/numerics/complex.number/complex.special/long_double_double_implicit.pass.cpp +++ b/test/numerics/complex.number/complex.special/long_double_double_implicit.pass.cpp @@ -20,8 +20,18 @@ int main() { + { const std::complex cd(2.5, 3.5); std::complex cf = cd; assert(cf.real() == cd.real()); assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex cd(2.5, 3.5); + constexpr std::complex cf = cd; + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif } diff --git a/test/numerics/complex.number/complex.special/long_double_float_explicit.pass.cpp b/test/numerics/complex.number/complex.special/long_double_float_explicit.pass.cpp index 5414f348..a5f5101c 100644 --- a/test/numerics/complex.number/complex.special/long_double_float_explicit.pass.cpp +++ b/test/numerics/complex.number/complex.special/long_double_float_explicit.pass.cpp @@ -20,8 +20,18 @@ int main() { + { const std::complex cd(2.5, 3.5); std::complex cf(cd); assert(cf.real() == cd.real()); assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex cd(2.5, 3.5); + constexpr std::complex cf(cd); + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif } diff --git a/test/numerics/complex.number/complex.special/long_double_float_implicit.pass.cpp b/test/numerics/complex.number/complex.special/long_double_float_implicit.pass.cpp index a0021782..25b93823 100644 --- a/test/numerics/complex.number/complex.special/long_double_float_implicit.pass.cpp +++ b/test/numerics/complex.number/complex.special/long_double_float_implicit.pass.cpp @@ -20,8 +20,18 @@ int main() { + { const std::complex cd(2.5, 3.5); std::complex cf = cd; assert(cf.real() == cd.real()); assert(cf.imag() == cd.imag()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + constexpr std::complex cd(2.5, 3.5); + constexpr std::complex cf = cd; + static_assert(cf.real() == cd.real(), ""); + static_assert(cf.imag() == cd.imag(), ""); + } +#endif }