mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
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]
This commit is contained in:
parent
f57c914b8f
commit
cb189bd6be
@ -79,7 +79,7 @@
|
|||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/iterator.hpp>
|
#include <boost/iterator.hpp>
|
||||||
#include <boost/preprocessor/seq/cat.hpp>
|
#include <boost/detail/workaround.hpp>
|
||||||
|
|
||||||
#if defined(__sgi) && !defined(__GNUC__)
|
#if defined(__sgi) && !defined(__GNUC__)
|
||||||
# pragma set woff 1234
|
# pragma set woff 1234
|
||||||
@ -155,7 +155,7 @@ struct equality_comparable1 : B
|
|||||||
};
|
};
|
||||||
|
|
||||||
// A macro which produces "name_2left" from "name".
|
// 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) ---------------//
|
// NRVO-friendly implementation (contributed by Daniel Frey) ---------------//
|
||||||
|
|
||||||
@ -317,8 +317,16 @@ struct bool_testable : B
|
|||||||
{
|
{
|
||||||
friend bool operator!(const T& t) { return !static_cast<bool>(t); }
|
friend bool operator!(const T& t) { return !static_cast<bool>(t); }
|
||||||
private:
|
private:
|
||||||
|
#if !BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 600)
|
||||||
typedef signed char private_number_type;
|
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;
|
operator private_number_type() const;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// More operator classes (contributed by Daryle Walker) --------------------//
|
// More operator classes (contributed by Daryle Walker) --------------------//
|
||||||
|
@ -51,7 +51,14 @@ namespace
|
|||||||
class Wrapped1
|
class Wrapped1
|
||||||
: boost::operators<Wrapped1<T> >
|
: boost::operators<Wrapped1<T> >
|
||||||
, boost::shiftable<Wrapped1<T> >
|
, boost::shiftable<Wrapped1<T> >
|
||||||
, boost::bool_testable<Wrapped1<T> >
|
,
|
||||||
|
#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<Wrapped1<T> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Wrapped1( T v = T() ) : _value(v) {}
|
explicit Wrapped1( T v = T() ) : _value(v) {}
|
||||||
@ -82,7 +89,9 @@ namespace
|
|||||||
{ _value >>= x._value; return *this; }
|
{ _value >>= x._value; return *this; }
|
||||||
Wrapped1& operator++() { ++_value; return *this; }
|
Wrapped1& operator++() { ++_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:
|
private:
|
||||||
T _value;
|
T _value;
|
||||||
@ -323,10 +332,19 @@ namespace
|
|||||||
test_multipliable_aux( y1, x1, y2, x2 );
|
test_multipliable_aux( y1, x1, y2, x2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class A, class B>
|
||||||
|
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 <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
void test_addable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
void test_addable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||||
{
|
{
|
||||||
BOOST_TEST( (x1 + y1).value() == (x2 + y2) );
|
TEST_OP_R(+);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
@ -341,14 +359,14 @@ namespace
|
|||||||
void test_subtractable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
void test_subtractable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||||
{
|
{
|
||||||
sanity_check( x1, y1, x2, y2 );
|
sanity_check( x1, y1, x2, y2 );
|
||||||
BOOST_TEST( (x1 - y1).value() == (x2 - y2) );
|
TEST_OP_R(-);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
void test_subtractable_left(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
void test_subtractable_left(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||||
{
|
{
|
||||||
sanity_check( x1, y1, x2, y2 );
|
sanity_check( x1, y1, x2, y2 );
|
||||||
BOOST_TEST( (y1 - x1).value() == (y2 - x2) );
|
TEST_OP_L(-);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
@ -356,7 +374,7 @@ namespace
|
|||||||
{
|
{
|
||||||
sanity_check( x1, y1, x2, y2 );
|
sanity_check( x1, y1, x2, y2 );
|
||||||
if ( y2 != 0 )
|
if ( y2 != 0 )
|
||||||
BOOST_TEST( (x1 / y1).value() == (x2 / y2) );
|
TEST_OP_R(/);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
@ -364,7 +382,7 @@ namespace
|
|||||||
{
|
{
|
||||||
sanity_check( x1, y1, x2, y2 );
|
sanity_check( x1, y1, x2, y2 );
|
||||||
if ( x2 != 0 )
|
if ( x2 != 0 )
|
||||||
BOOST_TEST( (y1 / x1).value() == (y2 / x2) );
|
TEST_OP_L(/);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
@ -372,7 +390,7 @@ namespace
|
|||||||
{
|
{
|
||||||
sanity_check( x1, y1, x2, y2 );
|
sanity_check( x1, y1, x2, y2 );
|
||||||
if ( y2 != 0 )
|
if ( y2 != 0 )
|
||||||
BOOST_TEST( (x1 % y1).value() == (x2 % y2) );
|
TEST_OP_R(%);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
@ -380,13 +398,13 @@ namespace
|
|||||||
{
|
{
|
||||||
sanity_check( x1, y1, x2, y2 );
|
sanity_check( x1, y1, x2, y2 );
|
||||||
if ( x2 != 0 )
|
if ( x2 != 0 )
|
||||||
BOOST_TEST( (y1 % x1).value() == (y2 % x2) );
|
TEST_OP_L(%);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
void test_xorable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
void test_xorable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||||
{
|
{
|
||||||
BOOST_TEST( (x1 ^ y1).value() == (x2 ^ y2) );
|
TEST_OP_R(^);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
@ -400,7 +418,7 @@ namespace
|
|||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
void test_andable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
void test_andable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||||
{
|
{
|
||||||
BOOST_TEST( (x1 & y1).value() == (x2 & y2) );
|
TEST_OP_R(&);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
@ -414,7 +432,7 @@ namespace
|
|||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
void test_orable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
void test_orable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||||
{
|
{
|
||||||
BOOST_TEST( (x1 | y1).value() == (x2 | y2) );
|
TEST_OP_R(|);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
@ -429,14 +447,14 @@ namespace
|
|||||||
void test_left_shiftable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
void test_left_shiftable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||||
{
|
{
|
||||||
sanity_check( x1, y1, x2, y2 );
|
sanity_check( x1, y1, x2, y2 );
|
||||||
BOOST_TEST( (x1 << y1).value() == (x2 << y2) );
|
TEST_OP_R(<<);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class Y1, class X2, class Y2>
|
template <class X1, class Y1, class X2, class Y2>
|
||||||
void test_right_shiftable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
void test_right_shiftable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||||
{
|
{
|
||||||
sanity_check( x1, y1, x2, y2 );
|
sanity_check( x1, y1, x2, y2 );
|
||||||
BOOST_TEST( (x1 >> y1).value() == (x2 >> y2) );
|
TEST_OP_R(>>);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X1, class X2>
|
template <class X1, class X2>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user