Index: libs/utility/operators_test.cpp =================================================================== RCS file: /cvsroot/boost/boost/libs/utility/operators_test.cpp,v retrieving revision 1.5 diff -u -r1.5 operators_test.cpp --- libs/utility/operators_test.cpp 12 Aug 2002 15:05:23 -0000 1.5 +++ libs/utility/operators_test.cpp 27 Feb 2003 10:49:47 -0000 @@ -50,6 +50,7 @@ class Wrapped1 : boost::operators > , boost::shiftable > + , public boost::bool_testable > { public: explicit Wrapped1( T v = T() ) : _value(v) {} @@ -80,6 +81,7 @@ { _value >>= x._value; return *this; } Wrapped1& operator++() { ++_value; return *this; } Wrapped1& operator--() { --_value; return *this; } + bool operator!() const { return _value == 0; } private: T _value; @@ -93,6 +95,7 @@ , boost::operators2, U> , boost::shiftable1 , boost::shiftable2, U > > + , public boost::bool_testable > { public: explicit Wrapped2( T v = T() ) : _value(v) {} @@ -137,6 +140,7 @@ Wrapped2& operator^=(U u) { _value ^= u; return *this; } Wrapped2& operator<<=(U u) { _value <<= u; return *this; } Wrapped2& operator>>=(U u) { _value >>= u; return *this; } + bool operator!() const { return _value == 0; } private: T _value; @@ -451,6 +455,14 @@ BOOST_TEST( (x1--).value() == x2-- ); BOOST_TEST( x1.value() == x2 ); } + + template + void test_bool_testable(X1 x1, X2 x2) + { + sanity_check( x1, x2, x1, x2 ); + BOOST_TEST(static_cast(x1) == (x2 != 0)); + BOOST_TEST(!x1 == (x2 == 0)); + } template void test_all(X1 x1, Y1 y1, X2 x2, Y2 y2) @@ -469,6 +481,7 @@ test_right_shiftable( x1, y1, x2, y2 ); test_incrementable( x1, x2 ); test_decrementable( x1, x2 ); + test_bool_testable( x1, x2); } template @@ -555,6 +568,7 @@ #define PRIVATE_EXPR_TEST(e, t) BOOST_TEST( ((e), (t)) ) +#define PRIVATE_BOOLEAN_EXPR_TEST(t, res) BOOST_TEST(static_cast((t)) == (res)) int test_main( int , char * [] ) @@ -631,6 +645,13 @@ PRIVATE_EXPR_TEST( (i = i1 << i2), (i.value() == 4) ); PRIVATE_EXPR_TEST( (i = i2 >> i1), (i.value() == 1) ); + + PRIVATE_BOOLEAN_EXPR_TEST( i, false); + PRIVATE_BOOLEAN_EXPR_TEST( i1, true); + PRIVATE_BOOLEAN_EXPR_TEST( i2, true); + PRIVATE_BOOLEAN_EXPR_TEST(!i, true); + PRIVATE_BOOLEAN_EXPR_TEST(!i1, false); + PRIVATE_BOOLEAN_EXPR_TEST(!i2, false); cout << "Performed tests on MyInt objects.\n"; @@ -719,6 +740,14 @@ BOOST_TEST( (j >> 2) == 1 ); BOOST_TEST( (j2 >> 1) == 1 ); PRIVATE_EXPR_TEST( (j = j2 >> j1), (j.value() == 1) ); + + + PRIVATE_BOOLEAN_EXPR_TEST( j, false); + PRIVATE_BOOLEAN_EXPR_TEST( j1, true); + PRIVATE_BOOLEAN_EXPR_TEST( j2, true); + PRIVATE_BOOLEAN_EXPR_TEST(!j, true); + PRIVATE_BOOLEAN_EXPR_TEST(!j1, false); + PRIVATE_BOOLEAN_EXPR_TEST(!j2, false); cout << "Performed tests on MyLong objects.\n";