diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 739edc0..55fdd44 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -21,6 +21,7 @@ run compressed_pair_final_test.cpp ; run iterators_test.cpp ; run operators_test.cpp ; +compile operators_constexpr_test.cpp ; compile result_of_test.cpp ; diff --git a/test/operators_constexpr_test.cpp b/test/operators_constexpr_test.cpp new file mode 100644 index 0000000..8ea3aff --- /dev/null +++ b/test/operators_constexpr_test.cpp @@ -0,0 +1,59 @@ +/* +Copyright 2020 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ + +#include +#if !defined(BOOST_NO_CXX11_CONSTEXPR) && \ + (!defined(BOOST_MSVC) || (BOOST_MSVC >= 1922)) +#include +#include + +namespace { + +class Value + : boost::operators { +public: + BOOST_OPS_CONSTEXPR explicit Value(int v) + : v_(v) { } + + BOOST_OPS_CONSTEXPR bool + operator<(const Value& x) const { + return v_ < x.v_; + } + + BOOST_OPS_CONSTEXPR bool + operator==(const Value& x) const { + return v_ == x.v_; + } + +private: + int v_; +}; + +} // namespace + +BOOST_STATIC_ASSERT(!static_cast(Value(1) == Value(2))); +BOOST_STATIC_ASSERT(Value(1) != Value(2)); +BOOST_STATIC_ASSERT(Value(1) < Value(2)); +BOOST_STATIC_ASSERT(Value(1) <= Value(2)); +BOOST_STATIC_ASSERT(!static_cast(Value(1) > Value(2))); +BOOST_STATIC_ASSERT(!static_cast(Value(1) >= Value(2))); + +BOOST_STATIC_ASSERT(!static_cast(Value(2) == Value(1))); +BOOST_STATIC_ASSERT(Value(2) != Value(1)); +BOOST_STATIC_ASSERT(!static_cast(Value(2) < Value(1))); +BOOST_STATIC_ASSERT(!static_cast(Value(2) <= Value(1))); +BOOST_STATIC_ASSERT(Value(2) > Value(1)); +BOOST_STATIC_ASSERT(Value(2) >= Value(1)); + +BOOST_STATIC_ASSERT(Value(1) == Value(1)); +BOOST_STATIC_ASSERT(!static_cast(Value(1) != Value(1))); +BOOST_STATIC_ASSERT(!static_cast(Value(1) < Value(1))); +BOOST_STATIC_ASSERT(Value(1) <= Value(1)); +BOOST_STATIC_ASSERT(!static_cast(Value(1) > Value(1))); +BOOST_STATIC_ASSERT(Value(1) >= Value(1)); +#endif diff --git a/test/operators_test.cpp b/test/operators_test.cpp index a98d6f6..c1edf8f 100644 --- a/test/operators_test.cpp +++ b/test/operators_test.cpp @@ -50,9 +50,9 @@ namespace void operator!() const; public: - BOOST_OPS_CONSTEXPR convertible_to_bool( const bool value ) : _value( value ) {} + convertible_to_bool( const bool value ) : _value( value ) {} - BOOST_OPS_CONSTEXPR operator unspecified_bool_type() const + operator unspecified_bool_type() const { return _value ? &convertible_to_bool::_value : 0; } }; @@ -64,12 +64,12 @@ namespace , boost::shiftable > { public: - BOOST_OPS_CONSTEXPR explicit Wrapped1( T v = T() ) : _value(v) {} - BOOST_OPS_CONSTEXPR T value() const { return _value; } + explicit Wrapped1( T v = T() ) : _value(v) {} + T value() const { return _value; } - BOOST_OPS_CONSTEXPR convertible_to_bool operator<(const Wrapped1& x) const + convertible_to_bool operator<(const Wrapped1& x) const { return _value < x._value; } - BOOST_OPS_CONSTEXPR convertible_to_bool operator==(const Wrapped1& x) const + convertible_to_bool operator==(const Wrapped1& x) const { return _value == x._value; } Wrapped1& operator+=(const Wrapped1& x) @@ -932,31 +932,5 @@ 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 -#if !defined(BOOST_MSVC) || (_MSC_VER >= 1922) - 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 -#endif - return boost::report_errors(); }