From cb189bd6bef20740aa35deb56fbca3caa77b2f64 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 30 Jul 2003 01:11:14 +0000 Subject: [PATCH] operators.hpp, operators_test.cpp - workaround for compilers not supporting the PP lib, many workarounds for another problem which may be our bug. linear_congruential.hpp - Borland workaround [SVN r19350] --- include/boost/operators.hpp | 12 +++++++-- operators_test.cpp | 50 +++++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/include/boost/operators.hpp b/include/boost/operators.hpp index 344bdf3..0270043 100644 --- a/include/boost/operators.hpp +++ b/include/boost/operators.hpp @@ -79,7 +79,7 @@ #include #include -#include +#include #if defined(__sgi) && !defined(__GNUC__) # pragma set woff 1234 @@ -155,7 +155,7 @@ struct equality_comparable1 : B }; // A macro which produces "name_2left" from "name". -#define BOOST_OPERATOR2_LEFT(name) BOOST_PP_SEQ_CAT_S(1,(name)(2)(_)(left)) +#define BOOST_OPERATOR2_LEFT(name) name##2##_##left // NRVO-friendly implementation (contributed by Daniel Frey) ---------------// @@ -317,8 +317,16 @@ struct bool_testable : B { friend bool operator!(const T& t) { return !static_cast(t); } private: +#if !BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 600) typedef signed char private_number_type; +# if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1301)) \ + || BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, BOOST_TESTED_AT(800)) \ + || BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(3)) \ + || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) + public: +# endif operator private_number_type() const; +#endif }; // More operator classes (contributed by Daryle Walker) --------------------// diff --git a/operators_test.cpp b/operators_test.cpp index 31660e0..317dd01 100644 --- a/operators_test.cpp +++ b/operators_test.cpp @@ -51,7 +51,14 @@ namespace class Wrapped1 : boost::operators > , boost::shiftable > - , boost::bool_testable > + , +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1300)) \ + || BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(3)) \ + || BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, BOOST_TESTED_AT(800)) \ + || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) + public +#endif + boost::bool_testable > { public: explicit Wrapped1( T v = T() ) : _value(v) {} @@ -82,7 +89,9 @@ namespace { _value >>= x._value; return *this; } Wrapped1& operator++() { ++_value; return *this; } Wrapped1& operator--() { --_value; return *this; } - operator bool() const { return _value != 0; } + + typedef T (Wrapped1::*safe_bool)() const; + operator safe_bool () const { return _value ? &Wrapped1::value : 0; } private: T _value; @@ -322,11 +331,20 @@ namespace test_multipliable_aux( x1, y1, x2, y2 ); test_multipliable_aux( y1, x1, y2, x2 ); } - + + template + void test_value_equality(A a, B b) + { + BOOST_TEST(a.value() == b); + } + +#define TEST_OP_R(op) test_value_equality(x1 op y1, x2 op y2) +#define TEST_OP_L(op) test_value_equality(y1 op x1, y2 op x2) + template void test_addable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) { - BOOST_TEST( (x1 + y1).value() == (x2 + y2) ); + TEST_OP_R(+); } template @@ -336,19 +354,19 @@ namespace test_addable_aux( x1, y1, x2, y2 ); test_addable_aux( y1, x1, y2, x2 ); } - + template void test_subtractable(X1 x1, Y1 y1, X2 x2, Y2 y2) { sanity_check( x1, y1, x2, y2 ); - BOOST_TEST( (x1 - y1).value() == (x2 - y2) ); + TEST_OP_R(-); } template void test_subtractable_left(X1 x1, Y1 y1, X2 x2, Y2 y2) { sanity_check( x1, y1, x2, y2 ); - BOOST_TEST( (y1 - x1).value() == (y2 - x2) ); + TEST_OP_L(-); } template @@ -356,7 +374,7 @@ namespace { sanity_check( x1, y1, x2, y2 ); if ( y2 != 0 ) - BOOST_TEST( (x1 / y1).value() == (x2 / y2) ); + TEST_OP_R(/); } template @@ -364,7 +382,7 @@ namespace { sanity_check( x1, y1, x2, y2 ); if ( x2 != 0 ) - BOOST_TEST( (y1 / x1).value() == (y2 / x2) ); + TEST_OP_L(/); } template @@ -372,7 +390,7 @@ namespace { sanity_check( x1, y1, x2, y2 ); if ( y2 != 0 ) - BOOST_TEST( (x1 % y1).value() == (x2 % y2) ); + TEST_OP_R(%); } template @@ -380,13 +398,13 @@ namespace { sanity_check( x1, y1, x2, y2 ); if ( x2 != 0 ) - BOOST_TEST( (y1 % x1).value() == (y2 % x2) ); + TEST_OP_L(%); } template void test_xorable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) { - BOOST_TEST( (x1 ^ y1).value() == (x2 ^ y2) ); + TEST_OP_R(^); } template @@ -400,7 +418,7 @@ namespace template void test_andable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) { - BOOST_TEST( (x1 & y1).value() == (x2 & y2) ); + TEST_OP_R(&); } template @@ -414,7 +432,7 @@ namespace template void test_orable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) { - BOOST_TEST( (x1 | y1).value() == (x2 | y2) ); + TEST_OP_R(|); } template @@ -429,14 +447,14 @@ namespace void test_left_shiftable(X1 x1, Y1 y1, X2 x2, Y2 y2) { sanity_check( x1, y1, x2, y2 ); - BOOST_TEST( (x1 << y1).value() == (x2 << y2) ); + TEST_OP_R(<<); } template void test_right_shiftable(X1 x1, Y1 y1, X2 x2, Y2 y2) { sanity_check( x1, y1, x2, y2 ); - BOOST_TEST( (x1 >> y1).value() == (x2 >> y2) ); + TEST_OP_R(>>); } template