diff --git a/include/boost/operators.hpp b/include/boost/operators.hpp index 156571c..0f4bca0 100644 --- a/include/boost/operators.hpp +++ b/include/boost/operators.hpp @@ -132,34 +132,34 @@ template class empty_base {}; template > struct less_than_comparable2 : B { - friend bool operator<=(const T& x, const U& y) { return !static_cast(x > y); } - friend bool operator>=(const T& x, const U& y) { return !static_cast(x < y); } - friend bool operator>(const U& x, const T& y) { return y < x; } - friend bool operator<(const U& x, const T& y) { return y > x; } - friend bool operator<=(const U& x, const T& y) { return !static_cast(y < x); } - friend bool operator>=(const U& x, const T& y) { return !static_cast(y > x); } + friend BOOST_CONSTEXPR bool operator<=(const T& x, const U& y) { return !static_cast(x > y); } + friend BOOST_CONSTEXPR bool operator>=(const T& x, const U& y) { return !static_cast(x < y); } + friend BOOST_CONSTEXPR bool operator>(const U& x, const T& y) { return y < x; } + friend BOOST_CONSTEXPR bool operator<(const U& x, const T& y) { return y > x; } + friend BOOST_CONSTEXPR bool operator<=(const U& x, const T& y) { return !static_cast(y < x); } + friend BOOST_CONSTEXPR bool operator>=(const U& x, const T& y) { return !static_cast(y > x); } }; template > struct less_than_comparable1 : B { - friend bool operator>(const T& x, const T& y) { return y < x; } - friend bool operator<=(const T& x, const T& y) { return !static_cast(y < x); } - friend bool operator>=(const T& x, const T& y) { return !static_cast(x < y); } + friend BOOST_CONSTEXPR bool operator>(const T& x, const T& y) { return y < x; } + friend BOOST_CONSTEXPR bool operator<=(const T& x, const T& y) { return !static_cast(y < x); } + friend BOOST_CONSTEXPR bool operator>=(const T& x, const T& y) { return !static_cast(x < y); } }; template > struct equality_comparable2 : B { - friend bool operator==(const U& y, const T& x) { return x == y; } - friend bool operator!=(const U& y, const T& x) { return !static_cast(x == y); } - friend bool operator!=(const T& y, const U& x) { return !static_cast(y == x); } + friend BOOST_CONSTEXPR bool operator==(const U& y, const T& x) { return x == y; } + friend BOOST_CONSTEXPR bool operator!=(const U& y, const T& x) { return !static_cast(x == y); } + friend BOOST_CONSTEXPR bool operator!=(const T& y, const U& x) { return !static_cast(y == x); } }; template > struct equality_comparable1 : B { - friend bool operator!=(const T& x, const T& y) { return !static_cast(x == y); } + friend BOOST_CONSTEXPR bool operator!=(const T& x, const T& y) { return !static_cast(x == y); } }; // A macro which produces "name_2left" from "name". @@ -174,43 +174,43 @@ struct equality_comparable1 : B // If the compiler has no NRVO, this is the best symmetric // implementation available. -#define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \ -template > \ -struct NAME##2 : B \ -{ \ - friend T operator OP( const T& lhs, const U& rhs ) \ - { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ - friend T operator OP( const U& lhs, const T& rhs ) \ - { T nrv( rhs ); nrv OP##= lhs; return nrv; } \ -}; \ - \ -template > \ -struct NAME##1 : B \ -{ \ - friend T operator OP( const T& lhs, const T& rhs ) \ - { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ +#define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \ +template > \ +struct NAME##2 : B \ +{ \ + friend BOOST_CXX14_CONSTEXPR T operator OP( const T& lhs, const U& rhs ) \ + { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ + friend BOOST_CXX14_CONSTEXPR T operator OP( const U& lhs, const T& rhs ) \ + { T nrv( rhs ); nrv OP##= lhs; return nrv; } \ +}; \ + \ +template > \ +struct NAME##1 : B \ +{ \ + friend BOOST_CXX14_CONSTEXPR T operator OP( const T& lhs, const T& rhs ) \ + { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ }; -#define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \ -template > \ -struct NAME##2 : B \ -{ \ - friend T operator OP( const T& lhs, const U& rhs ) \ - { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ -}; \ - \ -template > \ -struct BOOST_OPERATOR2_LEFT(NAME) : B \ -{ \ - friend T operator OP( const U& lhs, const T& rhs ) \ - { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ -}; \ - \ -template > \ -struct NAME##1 : B \ -{ \ - friend T operator OP( const T& lhs, const T& rhs ) \ - { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ +#define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \ +template > \ +struct NAME##2 : B \ +{ \ + friend BOOST_CXX14_CONSTEXPR T operator OP( const T& lhs, const U& rhs ) \ + { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ +}; \ + \ +template > \ +struct BOOST_OPERATOR2_LEFT(NAME) : B \ +{ \ + friend BOOST_CXX14_CONSTEXPR T operator OP( const U& lhs, const T& rhs ) \ + { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ +}; \ + \ +template > \ +struct NAME##1 : B \ +{ \ + friend BOOST_CXX14_CONSTEXPR T operator OP( const T& lhs, const T& rhs ) \ + { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ }; #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS) @@ -220,38 +220,38 @@ struct NAME##1 : B \ // BOOST_OPERATOR2_LEFT(NAME) only looks cool, but doesn't provide // optimization opportunities to the compiler :) -#define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \ -template > \ -struct NAME##2 : B \ -{ \ - friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \ - friend T operator OP( const U& lhs, T rhs ) { return rhs OP##= lhs; } \ -}; \ - \ -template > \ -struct NAME##1 : B \ -{ \ - friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \ +#define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \ +template > \ +struct NAME##2 : B \ +{ \ + friend BOOST_CONSTEXPR T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \ + friend BOOST_CONSTEXPR T operator OP( const U& lhs, T rhs ) { return rhs OP##= lhs; } \ +}; \ + \ +template > \ +struct NAME##1 : B \ +{ \ + friend BOOST_CONSTEXPR T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \ }; -#define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \ -template > \ -struct NAME##2 : B \ -{ \ - friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \ -}; \ - \ -template > \ -struct BOOST_OPERATOR2_LEFT(NAME) : B \ -{ \ - friend T operator OP( const U& lhs, const T& rhs ) \ - { return T( lhs ) OP##= rhs; } \ -}; \ - \ -template > \ -struct NAME##1 : B \ -{ \ - friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \ +#define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \ +template > \ +struct NAME##2 : B \ +{ \ + friend BOOST_CONSTEXPR T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \ +}; \ + \ +template > \ +struct BOOST_OPERATOR2_LEFT(NAME) : B \ +{ \ + friend BOOST_CONSTEXPR T operator OP( const U& lhs, const T& rhs ) \ + { return T( lhs ) OP##= rhs; } \ +}; \ + \ +template > \ +struct NAME##1 : B \ +{ \ + friend BOOST_CONSTEXPR T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \ }; #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS) @@ -274,7 +274,7 @@ BOOST_BINARY_OPERATOR_COMMUTATIVE( orable, | ) template > struct incrementable : B { - friend T operator++(T& x, int) + friend BOOST_CXX14_CONSTEXPR T operator++(T& x, int) { incrementable_type nrv(x); ++x; @@ -287,7 +287,7 @@ private: // The use of this typedef works around a Borland bug template > struct decrementable : B { - friend T operator--(T& x, int) + friend BOOST_CXX14_CONSTEXPR T operator--(T& x, int) { decrementable_type nrv(x); --x; @@ -322,34 +322,34 @@ struct indexable : B #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS) -#define BOOST_BINARY_OPERATOR( NAME, OP ) \ -template > \ -struct NAME##2 : B \ -{ \ - friend T operator OP( const T& lhs, const U& rhs ) \ - { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ -}; \ - \ -template > \ -struct NAME##1 : B \ -{ \ - friend T operator OP( const T& lhs, const T& rhs ) \ - { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ +#define BOOST_BINARY_OPERATOR( NAME, OP ) \ +template > \ +struct NAME##2 : B \ +{ \ + friend BOOST_CXX14_CONSTEXPR T operator OP( const T& lhs, const U& rhs ) \ + { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ +}; \ + \ +template > \ +struct NAME##1 : B \ +{ \ + friend BOOST_CXX14_CONSTEXPR T operator OP( const T& lhs, const T& rhs ) \ + { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ }; #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS) -#define BOOST_BINARY_OPERATOR( NAME, OP ) \ -template > \ -struct NAME##2 : B \ -{ \ - friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \ -}; \ - \ -template > \ -struct NAME##1 : B \ -{ \ - friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \ +#define BOOST_BINARY_OPERATOR( NAME, OP ) \ +template > \ +struct NAME##2 : B \ +{ \ + friend BOOST_CONSTEXPR T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \ +}; \ + \ +template > \ +struct NAME##1 : B \ +{ \ + friend BOOST_CONSTEXPR T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \ }; #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS) @@ -362,7 +362,7 @@ BOOST_BINARY_OPERATOR( right_shiftable, >> ) template > struct equivalent2 : B { - friend bool operator==(const T& x, const U& y) + friend BOOST_CONSTEXPR bool operator==(const T& x, const U& y) { return !static_cast(x < y) && !static_cast(x > y); } @@ -371,7 +371,7 @@ struct equivalent2 : B template > struct equivalent1 : B { - friend bool operator==(const T&x, const T&y) + friend BOOST_CONSTEXPR bool operator==(const T&x, const T&y) { return !static_cast(x < y) && !static_cast(y < x); } @@ -380,28 +380,28 @@ struct equivalent1 : B template > struct partially_ordered2 : B { - friend bool operator<=(const T& x, const U& y) + friend BOOST_CONSTEXPR bool operator<=(const T& x, const U& y) { return static_cast(x < y) || static_cast(x == y); } - friend bool operator>=(const T& x, const U& y) + friend BOOST_CONSTEXPR bool operator>=(const T& x, const U& y) { return static_cast(x > y) || static_cast(x == y); } - friend bool operator>(const U& x, const T& y) + friend BOOST_CONSTEXPR bool operator>(const U& x, const T& y) { return y < x; } - friend bool operator<(const U& x, const T& y) + friend BOOST_CONSTEXPR bool operator<(const U& x, const T& y) { return y > x; } - friend bool operator<=(const U& x, const T& y) + friend BOOST_CONSTEXPR bool operator<=(const U& x, const T& y) { return static_cast(y > x) || static_cast(y == x); } - friend bool operator>=(const U& x, const T& y) + friend BOOST_CONSTEXPR bool operator>=(const U& x, const T& y) { return static_cast(y < x) || static_cast(y == x); } }; template > struct partially_ordered1 : B { - friend bool operator>(const T& x, const T& y) + friend BOOST_CONSTEXPR bool operator>(const T& x, const T& y) { return y < x; } - friend bool operator<=(const T& x, const T& y) + friend BOOST_CONSTEXPR bool operator<=(const T& x, const T& y) { return static_cast(x < y) || static_cast(x == y); } - friend bool operator>=(const T& x, const T& y) + friend BOOST_CONSTEXPR bool operator>=(const T& x, const T& y) { return static_cast(y < x) || static_cast(x == y); } }; diff --git a/operators.htm b/operators.htm index db81fd3..f1613c5 100644 --- a/operators.htm +++ b/operators.htm @@ -454,7 +454,7 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); - + + + @@ -496,6 +498,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -513,6 +517,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -524,6 +530,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -537,6 +545,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -548,6 +558,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -560,6 +572,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -572,6 +586,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -584,6 +600,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -594,6 +612,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -606,6 +626,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -619,6 +641,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -630,6 +654,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -641,6 +667,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -651,6 +679,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -662,6 +692,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -673,6 +705,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -683,6 +717,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -694,6 +730,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -706,6 +744,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -717,6 +757,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -729,6 +771,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -740,6 +784,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -752,6 +798,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -762,6 +810,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -772,6 +822,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -784,6 +836,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -796,6 +850,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -808,6 +864,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -820,6 +878,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -831,6 +891,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -842,6 +904,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -856,6 +920,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); + + @@ -874,6 +940,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); u.
Returns convertible to bool. See the Ordering Note. + +
Key @@ -482,6 +482,8 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4);
Supplied Operations RequirementsPropagates constexpr?
t < t1.
Return convertible to bool. See the Ordering Note.
Since C++11
t < u. t > u.
Returns convertible to bool. See the Ordering Note.
Since C++11
t == t1.
Return convertible to bool.
Since C++11
t == u.
Return convertible to bool.
Since C++11
T temp(t); temp += t1.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp += u.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp -= t1.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp -= u.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(u); temp -= t.
Return convertible to T.
Since C++14
T temp(t); temp *= t1.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp *= u.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp /= t1.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp /= u.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(u); temp /= t.
Return convertible to T.
Since C++14
T temp(t); temp %= t1.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp %= u.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(u); temp %= t.
Return convertible to T.
Since C++14
T temp(t); temp |= t1.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp |= u.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp &= t1.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp &= u.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp ^= t1.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp ^= u.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); ++t
Return convertible to T.
Since C++14
T temp(t); --t;
Return convertible to T.
Since C++14
T temp(t); temp <<= t1.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp <<= u.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp >>= t1.
Return convertible to T. See the Symmetry Note.
Since C++14
T temp(t); temp >>= u.
Return convertible to T. See the Symmetry Note.
Since C++14
t < t1.
Return convertible to bool. See the Ordering Note.
Since C++11
t < u. t > u.
Returns convertible to bool. See the Ordering Note.
Since C++11
t < t1. t == t1.
Returns convertible to bool. See the Ordering Note.
Since C++11
Since C++11
diff --git a/test/operators_test.cpp b/test/operators_test.cpp index 6cf7a76..786ba3b 100644 --- a/test/operators_test.cpp +++ b/test/operators_test.cpp @@ -50,9 +50,9 @@ namespace void operator!() const; public: - convertible_to_bool( const bool value ) : _value( value ) {} + BOOST_CONSTEXPR convertible_to_bool( const bool value ) : _value( value ) {} - operator unspecified_bool_type() const + BOOST_CONSTEXPR operator unspecified_bool_type() const { return _value ? &convertible_to_bool::_value : 0; } }; @@ -64,36 +64,36 @@ namespace , boost::shiftable > { public: - explicit Wrapped1( T v = T() ) : _value(v) {} - T value() const { return _value; } + BOOST_CONSTEXPR explicit Wrapped1( T v = T() ) : _value(v) {} + BOOST_CONSTEXPR T value() const { return _value; } - convertible_to_bool operator<(const Wrapped1& x) const + BOOST_CONSTEXPR convertible_to_bool operator<(const Wrapped1& x) const { return _value < x._value; } - convertible_to_bool operator==(const Wrapped1& x) const + BOOST_CONSTEXPR convertible_to_bool operator==(const Wrapped1& x) const { return _value == x._value; } - Wrapped1& operator+=(const Wrapped1& x) + BOOST_CXX14_CONSTEXPR Wrapped1& operator+=(const Wrapped1& x) { _value += x._value; return *this; } - Wrapped1& operator-=(const Wrapped1& x) + BOOST_CXX14_CONSTEXPR Wrapped1& operator-=(const Wrapped1& x) { _value -= x._value; return *this; } - Wrapped1& operator*=(const Wrapped1& x) + BOOST_CXX14_CONSTEXPR Wrapped1& operator*=(const Wrapped1& x) { _value *= x._value; return *this; } - Wrapped1& operator/=(const Wrapped1& x) + BOOST_CXX14_CONSTEXPR Wrapped1& operator/=(const Wrapped1& x) { _value /= x._value; return *this; } - Wrapped1& operator%=(const Wrapped1& x) + BOOST_CXX14_CONSTEXPR Wrapped1& operator%=(const Wrapped1& x) { _value %= x._value; return *this; } - Wrapped1& operator|=(const Wrapped1& x) + BOOST_CXX14_CONSTEXPR Wrapped1& operator|=(const Wrapped1& x) { _value |= x._value; return *this; } - Wrapped1& operator&=(const Wrapped1& x) + BOOST_CXX14_CONSTEXPR Wrapped1& operator&=(const Wrapped1& x) { _value &= x._value; return *this; } - Wrapped1& operator^=(const Wrapped1& x) + BOOST_CXX14_CONSTEXPR Wrapped1& operator^=(const Wrapped1& x) { _value ^= x._value; return *this; } - Wrapped1& operator<<=(const Wrapped1& x) + BOOST_CXX14_CONSTEXPR Wrapped1& operator<<=(const Wrapped1& x) { _value <<= x._value; return *this; } - Wrapped1& operator>>=(const Wrapped1& x) + BOOST_CXX14_CONSTEXPR Wrapped1& operator>>=(const Wrapped1& x) { _value >>= x._value; return *this; } - Wrapped1& operator++() { ++_value; return *this; } - Wrapped1& operator--() { --_value; return *this; } + BOOST_CXX14_CONSTEXPR Wrapped1& operator++() { ++_value; return *this; } + BOOST_CXX14_CONSTEXPR Wrapped1& operator--() { --_value; return *this; } private: T _value; @@ -932,5 +932,64 @@ main() cout << "Performed tests on MyLongInt objects.\n"; +// Where C++11 constexpr is available, compile-time test some of the operators that are able to use it to propagate constexpr +#ifndef BOOST_NO_CXX11_CONSTEXPR + static_assert( ! static_cast( MyInt{ 1 } == MyInt{ 2 } ), "" ); + static_assert( MyInt{ 1 } != MyInt{ 2 }, "" ); + static_assert( MyInt{ 1 } < MyInt{ 2 }, "" ); + static_assert( MyInt{ 1 } <= MyInt{ 2 }, "" ); + static_assert( ! static_cast( MyInt{ 1 } > MyInt{ 2 } ), "" ); + static_assert( ! static_cast( MyInt{ 1 } >= MyInt{ 2 } ), "" ); + + static_assert( ! static_cast( MyInt{ 2 } == MyInt{ 1 } ), "" ); + static_assert( MyInt{ 2 } != MyInt{ 1 }, "" ); + static_assert( ! static_cast( MyInt{ 2 } < MyInt{ 1 } ), "" ); + static_assert( ! static_cast( MyInt{ 2 } <= MyInt{ 1 } ), "" ); + static_assert( MyInt{ 2 } > MyInt{ 1 }, "" ); + static_assert( MyInt{ 2 } >= MyInt{ 1 }, "" ); + + static_assert( MyInt{ 1 } == MyInt{ 1 }, "" ); + static_assert( ! static_cast( MyInt{ 1 } != MyInt{ 1 } ), "" ); + static_assert( ! static_cast( MyInt{ 1 } < MyInt{ 1 } ), "" ); + static_assert( MyInt{ 1 } <= MyInt{ 1 }, "" ); + static_assert( ! static_cast( MyInt{ 1 } > MyInt{ 1 } ), "" ); + static_assert( MyInt{ 1 } >= MyInt{ 1 }, "" ); +#endif + +// Where C++14 constexpr is available, compile-time test some of the operators that are able to use it to propagate constexpr +#ifndef BOOST_NO_CXX14_CONSTEXPR + static_assert( ( MyInt{ 1 } + MyInt{ 2 } ) == MyInt{ 3 }, "" ); + static_assert( ( MyInt{ 2 } + MyInt{ 1 } ) == MyInt{ 3 }, "" ); + static_assert( ( MyInt{ 2 } + MyInt{ 1 } ) == MyInt{ 3 }, "" ); + static_assert( ( MyInt{ 2 } + MyInt{ 2 } ) == MyInt{ 4 }, "" ); + static_assert( ( MyInt{ 3 } + MyInt{ 2 } ) == MyInt{ 5 }, "" ); + + static_assert( ( MyInt{ 5 } - MyInt{ 1 } ) == MyInt{ 4 }, "" ); + + static_assert( ( MyInt{ 3 } * MyInt{ 3 } ) == MyInt{ 9 }, "" ); + static_assert( ( MyInt{ 4 } * MyInt{ 2 } ) == MyInt{ 8 }, "" ); + + static_assert( ( MyInt{ 8 } / MyInt{ 2 } ) == MyInt{ 4 }, "" ); + + static_assert( ( MyInt{ 4 } % MyInt{ 3 } ) == MyInt{ 1 }, "" ); + + + static_assert( ( MyInt{ 7 } & MyInt{ 2 } ) == MyInt{ 2 }, "" ); + + static_assert( ( MyInt{ 1 } | MyInt{ 2 } ) == MyInt{ 3 }, "" ); + static_assert( ( MyInt{ 1 } | MyInt{ 4 } ) == MyInt{ 5 }, "" ); + static_assert( ( MyInt{ 2 } | MyInt{ 1 } ) == MyInt{ 3 }, "" ); + static_assert( ( MyInt{ 2 } | MyInt{ 4 } ) == MyInt{ 6 }, "" ); + static_assert( ( MyInt{ 3 } | MyInt{ 4 } ) == MyInt{ 7 }, "" ); + static_assert( ( MyInt{ 5 } | MyInt{ 2 } ) == MyInt{ 7 }, "" ); + static_assert( ( MyInt{ 6 } | MyInt{ 1 } ) == MyInt{ 7 }, "" ); + + static_assert( ( MyInt{ 3 } ^ MyInt{ 1 } ) == MyInt{ 2 }, "" ); + + + static_assert( ( MyInt{ 1 } << MyInt{ 2 } ) == MyInt{ 4 }, "" ); + static_assert( ( MyInt{ 2 } >> MyInt{ 1 } ) == MyInt{ 1 }, "" ); +#endif + return boost::report_errors(); }