public:
typedef T value_type;
- complex(const T& re = T(), const T& im = T());
- complex(const complex&);
- template<class X> complex(const complex<X>&);
+ complex(const T& re = T(), const T& im = T()); // constexpr in C++14
+ complex(const complex&); // constexpr in C++14
+ template<class X> complex(const complex<X>&); // constexpr in C++14
- T real() const;
- T imag() const;
+ T real() const; // constexpr in C++14
+ T imag() const; // constexpr in C++14
void real(T);
void imag(T);
template<class T> complex<T> operator/(const T&, const complex<T>&);
template<class T> complex<T> operator+(const complex<T>&);
template<class T> complex<T> operator-(const complex<T>&);
-template<class T> bool operator==(const complex<T>&, const complex<T>&);
-template<class T> bool operator==(const complex<T>&, const T&);
-template<class T> bool operator==(const T&, const complex<T>&);
-template<class T> bool operator!=(const complex<T>&, const complex<T>&);
-template<class T> bool operator!=(const complex<T>&, const T&);
-template<class T> bool operator!=(const T&, const complex<T>&);
+template<class T> bool operator==(const complex<T>&, const complex<T>&); // constexpr in C++14
+template<class T> bool operator==(const complex<T>&, const T&); // constexpr in C++14
+template<class T> bool operator==(const T&, const complex<T>&); // constexpr in C++14
+template<class T> bool operator!=(const complex<T>&, const complex<T>&); // constexpr in C++14
+template<class T> bool operator!=(const complex<T>&, const T&); // constexpr in C++14
+template<class T> bool operator!=(const T&, const complex<T>&); // constexpr in C++14
template<class T, class charT, class traits>
basic_istream<charT, traits>&
// 26.3.7 values:
-template<class T> T real(const complex<T>&);
- long double real(long double);
- double real(double);
-template<Integral T> double real(T);
- float real(float);
+template<class T> T real(const complex<T>&); // constexpr in C++14
+ long double real(long double); // constexpr in C++14
+ double real(double); // constexpr in C++14
+template<Integral T> double real(T); // constexpr in C++14
+ float real(float); // constexpr in C++14
-template<class T> T imag(const complex<T>&);
- long double imag(long double);
- double imag(double);
-template<Integral T> double imag(T);
- float imag(float);
+template<class T> T imag(const complex<T>&); // constexpr in C++14
+ long double imag(long double); // constexpr in C++14
+ double imag(double); // constexpr in C++14
+template<Integral T> double imag(T); // constexpr in C++14
+ float imag(float); // constexpr in C++14
template<class T> T abs(const complex<T>&);
value_type __re_;
value_type __im_;
public:
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
complex(const value_type& __re = value_type(), const value_type& __im = value_type())
: __re_(__re), __im_(__im) {}
- template<class _Xp> _LIBCPP_INLINE_VISIBILITY
+ template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
complex(const complex<_Xp>& __c)
: __re_(__c.real()), __im_(__c.imag()) {}
- _LIBCPP_INLINE_VISIBILITY value_type real() const {return __re_;}
- _LIBCPP_INLINE_VISIBILITY value_type imag() const {return __im_;}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type real() const {return __re_;}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type imag() const {return __im_;}
_LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
_LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
{
- *this = *this * __c;
+ *this = *this * complex(__c.real(), __c.imag());
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
{
- *this = *this / __c;
+ *this = *this / complex(__c.real(), __c.imag());
return *this;
}
};
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
{
- *this = *this * __c;
+ *this = *this * complex(__c.real(), __c.imag());
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
{
- *this = *this / __c;
+ *this = *this / complex(__c.real(), __c.imag());
return *this;
}
};
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
{
- *this = *this * __c;
+ *this = *this * complex(__c.real(), __c.imag());
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
{
- *this = *this / __c;
+ *this = *this / complex(__c.real(), __c.imag());
return *this;
}
};
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
{
- *this = *this * __c;
+ *this = *this * complex(__c.real(), __c.imag());
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
{
- *this = *this / __c;
+ *this = *this / complex(__c.real(), __c.imag());
return *this;
}
};
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
{
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator==(const complex<_Tp>& __x, const _Tp& __y)
{
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator==(const _Tp& __x, const complex<_Tp>& __y)
{
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y)
{
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator!=(const complex<_Tp>& __x, const _Tp& __y)
{
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator!=(const _Tp& __x, const complex<_Tp>& __y)
{
// real
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
real(const complex<_Tp>& __c)
{
return __c.real();
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
long double
real(long double __re)
{
return __re;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
double
real(double __re)
{
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename enable_if
<
is_integral<_Tp>::value,
return __re;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
float
real(float __re)
{
// imag
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
imag(const complex<_Tp>& __c)
{
return __c.imag();
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
long double
imag(long double __re)
{
return 0;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
double
imag(double __re)
{
}
template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename enable_if
<
is_integral<_Tp>::value,
return 0;
}
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
float
imag(float __re)
{
#include "../cases.h"
-template <class T>
+template <class T, int x>
void
-test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
+test(typename std::enable_if<std::is_integral<T>::value>::type* = 0)
{
- static_assert((std::is_same<decltype(std::imag(x)), double>::value), "");
+ static_assert((std::is_same<decltype(std::imag(T(x))), double>::value), "");
assert(std::imag(x) == 0);
+#if _LIBCPP_STD_VER > 11
+ constexpr T val {x};
+ static_assert(std::imag(val) == 0, "");
+ constexpr std::complex<T> t{val, val};
+ static_assert(t.imag() == x, "" );
+#endif
}
-template <class T>
+template <class T, int x>
void
-test(T x, typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
+test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
{
- static_assert((std::is_same<decltype(std::imag(x)), T>::value), "");
+ static_assert((std::is_same<decltype(std::imag(T(x))), T>::value), "");
assert(std::imag(x) == 0);
+#if _LIBCPP_STD_VER > 11
+ constexpr T val {x};
+ static_assert(std::imag(val) == 0, "");
+ constexpr std::complex<T> t{val, val};
+ static_assert(t.imag() == x, "" );
+#endif
}
template <class T>
void
test()
{
- test<T>(0);
- test<T>(1);
- test<T>(10);
+ test<T, 0>();
+ test<T, 1>();
+ test<T, 10>();
}
int main()
#include "../cases.h"
-template <class T>
+template <class T, int x>
void
-test(T x, typename std::enable_if<std::is_integral<T>::value>::type* = 0)
+test(typename std::enable_if<std::is_integral<T>::value>::type* = 0)
{
- static_assert((std::is_same<decltype(std::real(x)), double>::value), "");
+ static_assert((std::is_same<decltype(std::real(T(x))), double>::value), "");
assert(std::real(x) == x);
+#if _LIBCPP_STD_VER > 11
+ constexpr T val {x};
+ static_assert(std::real(val) == val, "");
+ constexpr std::complex<T> t{val, val};
+ static_assert(t.real() == x, "" );
+#endif
}
-template <class T>
+template <class T, int x>
void
-test(T x, typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
+test(typename std::enable_if<!std::is_integral<T>::value>::type* = 0)
{
- static_assert((std::is_same<decltype(std::real(x)), T>::value), "");
+ static_assert((std::is_same<decltype(std::real(T(x))), T>::value), "");
assert(std::real(x) == x);
+#if _LIBCPP_STD_VER > 11
+ constexpr T val {x};
+ static_assert(std::real(val) == val, "");
+ constexpr std::complex<T> t{val, val};
+ static_assert(t.real() == x, "" );
+#endif
}
template <class T>
void
test()
{
- test<T>(0);
- test<T>(1);
- test<T>(10);
+ test<T, 0>();
+ test<T, 1>();
+ test<T, 10>();
}
int main()
c /= c2;
assert(c.real() == 1);
assert(c.imag() == 0);
+
+ std::complex<T> c3;
+
+ c3 = c;
+ std::complex<int> ic (1,1);
+ c3 /= ic;
+ assert(c3.real() == 0.5);
+ assert(c3.imag() == -0.5);
+
+ c3 = c;
+ std::complex<float> fc (1,1);
+ c3 /= fc;
+ assert(c3.real() == 0.5);
+ assert(c3.imag() == -0.5);
+
}
int main()
c -= c2;
assert(c.real() == -3);
assert(c.imag() == -5);
+
+ std::complex<T> c3;
+
+ c3 = c;
+ std::complex<int> ic (1,1);
+ c3 -= ic;
+ assert(c3.real() == -4);
+ assert(c3.imag() == -6);
+
+ c3 = c;
+ std::complex<float> fc (1,1);
+ c3 -= fc;
+ assert(c3.real() == -4);
+ assert(c3.imag() == -6);
}
int main()
c += c2;
assert(c.real() == 3);
assert(c.imag() == 5);
+
+ std::complex<T> c3;
+
+ c3 = c;
+ std::complex<int> ic (1,1);
+ c3 += ic;
+ assert(c3.real() == 4);
+ assert(c3.imag() == 6);
+
+ c3 = c;
+ std::complex<float> fc (1,1);
+ c3 += fc;
+ assert(c3.real() == 4);
+ assert(c3.imag() == 6);
}
int main()
c *= c2;
assert(c.real() == -4);
assert(c.imag() == 7.5);
+
+ std::complex<T> c3;
+
+ c3 = c;
+ std::complex<int> ic (1,1);
+ c3 *= ic;
+ assert(c3.real() == -11.5);
+ assert(c3.imag() == 3.5);
+
+ c3 = c;
+ std::complex<float> fc (1,1);
+ c3 *= fc;
+ assert(c3.real() == -11.5);
+ assert(c3.imag() == 3.5);
}
int main()
template <class T>
void
+test_constexpr()
+{
+#if _LIBCPP_STD_VER > 11
+ constexpr std::complex<T> c1;
+ static_assert(c1.real() == 0, "");
+ static_assert(c1.imag() == 0, "");
+ constexpr std::complex<T> c2(3);
+ static_assert(c2.real() == 3, "");
+ static_assert(c2.imag() == 0, "");
+ constexpr std::complex<T> c3(3, 4);
+ static_assert(c3.real() == 3, "");
+ static_assert(c3.imag() == 4, "");
+#endif
+}
+
+template <class T>
+void
test()
{
std::complex<T> c;
c.imag(-5.5);
assert(c.real() == -4.5);
assert(c.imag() == -5.5);
+
+ test_constexpr<T> ();
}
int main()
test<float>();
test<double>();
test<long double>();
+ test_constexpr<int> ();
}
template <class T>
void
-test(const std::complex<T>& lhs, const std::complex<T>& rhs, bool x)
+test_constexpr()
{
- assert((lhs == rhs) == x);
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr std::complex<T> lhs(1.5, 2.5);
+ constexpr std::complex<T> rhs(1.5, -2.5);
+ static_assert( !(lhs == rhs), "");
+ }
+ {
+ constexpr std::complex<T> lhs(1.5, 2.5);
+ constexpr std::complex<T> rhs(1.5, 2.5);
+ static_assert(lhs == rhs, "");
+ }
+#endif
}
template <class T>
{
std::complex<T> lhs(1.5, 2.5);
std::complex<T> rhs(1.5, -2.5);
- test(lhs, rhs, false);
+ assert( !(lhs == rhs));
}
{
std::complex<T> lhs(1.5, 2.5);
std::complex<T> rhs(1.5, 2.5);
- test(lhs, rhs, true);
+ assert(lhs == rhs);
}
+ test_constexpr<T> ();
}
int main()
test<float>();
test<double>();
test<long double>();
+// test_constexpr<int> ();
}
template <class T>
void
-test(const std::complex<T>& lhs, const T& rhs, bool x)
+test_constexpr()
{
- assert((lhs == rhs) == x);
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr std::complex<T> lhs(1.5, 2.5);
+ constexpr T rhs(-2.5);
+ static_assert(!(lhs == rhs), "");
+ }
+ {
+ constexpr std::complex<T> lhs(1.5, 0);
+ constexpr T rhs(-2.5);
+ static_assert(!(lhs == rhs), "");
+ }
+ {
+ constexpr std::complex<T> lhs(1.5, 2.5);
+ constexpr T rhs(1.5);
+ static_assert(!(lhs == rhs), "");
+ }
+ {
+ constexpr std::complex<T> lhs(1.5, 0);
+ constexpr T rhs(1.5);
+ static_assert( (lhs == rhs), "");
+ }
+#endif
}
template <class T>
{
std::complex<T> lhs(1.5, 2.5);
T rhs(-2.5);
- test(lhs, rhs, false);
+ assert(!(lhs == rhs));
}
{
- std::complex<T> lhs(1.5, 0);
+ std::complex<T> lhs(1.5, 0);
T rhs(-2.5);
- test(lhs, rhs, false);
+ assert(!(lhs == rhs));
}
{
std::complex<T> lhs(1.5, 2.5);
T rhs(1.5);
- test(lhs, rhs, false);
+ assert(!(lhs == rhs));
}
{
std::complex<T> lhs(1.5, 0);
T rhs(1.5);
- test(lhs, rhs, true);
+ assert( (lhs == rhs));
+ }
+
+ test_constexpr<T> ();
}
-}
int main()
{
test<float>();
test<double>();
test<long double>();
+// test_constexpr<int> ();
}
template <class T>
void
-test(const std::complex<T>& lhs, const std::complex<T>& rhs, bool x)
+test_constexpr()
{
- assert((lhs != rhs) == x);
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr std::complex<T> lhs(1.5, 2.5);
+ constexpr std::complex<T> rhs(1.5, -2.5);
+ static_assert(lhs != rhs, "");
+ }
+ {
+ constexpr std::complex<T> lhs(1.5, 2.5);
+ constexpr std::complex<T> rhs(1.5, 2.5);
+ static_assert(!(lhs != rhs), "" );
+ }
+#endif
}
+
template <class T>
void
test()
{
std::complex<T> lhs(1.5, 2.5);
std::complex<T> rhs(1.5, -2.5);
- test(lhs, rhs, true);
+ assert(lhs != rhs);
}
{
std::complex<T> lhs(1.5, 2.5);
std::complex<T> rhs(1.5, 2.5);
- test(lhs, rhs, false);
+ assert(!(lhs != rhs));
}
-}
+
+ test_constexpr<T> ();
+ }
int main()
{
test<float>();
test<double>();
test<long double>();
+// test_constexpr<int> ();
}
template <class T>
void
-test(const std::complex<T>& lhs, const T& rhs, bool x)
+test_constexpr()
{
- assert((lhs != rhs) == x);
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr std::complex<T> lhs(1.5, 2.5);
+ constexpr T rhs(-2.5);
+ static_assert(lhs != rhs, "");
+ }
+ {
+ constexpr std::complex<T> lhs(1.5, 0);
+ constexpr T rhs(-2.5);
+ static_assert(lhs != rhs, "");
+ }
+ {
+ constexpr std::complex<T> lhs(1.5, 2.5);
+ constexpr T rhs(1.5);
+ static_assert(lhs != rhs, "");
+ }
+ {
+ constexpr std::complex<T> lhs(1.5, 0);
+ constexpr T rhs(1.5);
+ static_assert( !(lhs != rhs), "");
+ }
+#endif
}
template <class T>
{
std::complex<T> lhs(1.5, 2.5);
T rhs(-2.5);
- test(lhs, rhs, true);
+ assert(lhs != rhs);
}
{
std::complex<T> lhs(1.5, 0);
T rhs(-2.5);
- test(lhs, rhs, true);
+ assert(lhs != rhs);
}
{
std::complex<T> lhs(1.5, 2.5);
T rhs(1.5);
- test(lhs, rhs, true);
+ assert(lhs != rhs);
}
{
std::complex<T> lhs(1.5, 0);
T rhs(1.5);
- test(lhs, rhs, false);
+ assert( !(lhs != rhs));
}
+
+ test_constexpr<T> ();
}
int main()
test<float>();
test<double>();
test<long double>();
-}
+// test_constexpr<int> ();
+ }
template <class T>
void
-test(const T& lhs, const std::complex<T>& rhs, bool x)
+test_constexpr()
{
- assert((lhs == rhs) == x);
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr T lhs(-2.5);
+ constexpr std::complex<T> rhs(1.5, 2.5);
+ static_assert(!(lhs == rhs), "");
+ }
+ {
+ constexpr T lhs(-2.5);
+ constexpr std::complex<T> rhs(1.5, 0);
+ static_assert(!(lhs == rhs), "");
+ }
+ {
+ constexpr T lhs(1.5);
+ constexpr std::complex<T> rhs(1.5, 2.5);
+ static_assert(!(lhs == rhs), "");
+ }
+ {
+ constexpr T lhs(1.5);
+ constexpr std::complex<T> rhs(1.5, 0);
+ static_assert(lhs == rhs, "");
+ }
+#endif
}
template <class T>
{
T lhs(-2.5);
std::complex<T> rhs(1.5, 2.5);
- test(lhs, rhs, false);
+ assert(!(lhs == rhs));
}
{
T lhs(-2.5);
std::complex<T> rhs(1.5, 0);
- test(lhs, rhs, false);
+ assert(!(lhs == rhs));
}
{
T lhs(1.5);
std::complex<T> rhs(1.5, 2.5);
- test(lhs, rhs, false);
+ assert(!(lhs == rhs));
}
{
T lhs(1.5);
std::complex<T> rhs(1.5, 0);
- test(lhs, rhs, true);
+ assert(lhs == rhs);
}
+
+ test_constexpr<T> ();
}
int main()
test<float>();
test<double>();
test<long double>();
+// test_constexpr<int>();
}
template <class T>
void
-test(const T& lhs, const std::complex<T>& rhs, bool x)
+test_constexpr()
{
- assert((lhs != rhs) == x);
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr T lhs(-2.5);
+ constexpr std::complex<T> rhs(1.5, 2.5);
+ static_assert (lhs != rhs, "");
+ }
+ {
+ constexpr T lhs(-2.5);
+ constexpr std::complex<T> rhs(1.5, 0);
+ static_assert (lhs != rhs, "");
+ }
+ {
+ constexpr T lhs(1.5);
+ constexpr std::complex<T> rhs(1.5, 2.5);
+ static_assert (lhs != rhs, "");
+ }
+ {
+ constexpr T lhs(1.5);
+ constexpr std::complex<T> rhs(1.5, 0);
+ static_assert (!(lhs != rhs), "");
+ }
+#endif
}
template <class T>
{
T lhs(-2.5);
std::complex<T> rhs(1.5, 2.5);
- test(lhs, rhs, true);
+ assert (lhs != rhs);
}
{
T lhs(-2.5);
std::complex<T> rhs(1.5, 0);
- test(lhs, rhs, true);
+ assert (lhs != rhs);
}
{
T lhs(1.5);
std::complex<T> rhs(1.5, 2.5);
- test(lhs, rhs, true);
+ assert (lhs != rhs);
}
{
T lhs(1.5);
std::complex<T> rhs(1.5, 0);
- test(lhs, rhs, false);
+ assert (!(lhs != rhs));
+ }
+
+ test_constexpr<T> ();
}
-}
int main()
{
test<float>();
test<double>();
test<long double>();
+// test_constexpr<int>();
}