From be50b9550803fe946dbc15d5cedd417259b257e4 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Thu, 10 Apr 2008 14:38:14 +0000 Subject: [PATCH 01/30] Added test and fix for "convertible to bool" requirement [SVN r44151] --- include/boost/operators.hpp | 36 ++-- operators_test.cpp | 404 ++++++++++++++++++++---------------- 2 files changed, 243 insertions(+), 197 deletions(-) diff --git a/include/boost/operators.hpp b/include/boost/operators.hpp index b3b1bd7..3443cb5 100644 --- a/include/boost/operators.hpp +++ b/include/boost/operators.hpp @@ -8,6 +8,8 @@ // See http://www.boost.org/libs/utility/operators.htm for documentation. // Revision History +// 03 Apr 08 Make sure "convertible to bool" is sufficient +// for T::operator<, etc. (Daniel Frey) // 24 May 07 Changed empty_base to depend on T, see // http://svn.boost.org/trac/boost/ticket/979 // 21 Oct 02 Modified implementation of operators to allow compilers with a @@ -124,34 +126,34 @@ namespace boost template > struct less_than_comparable2 : B { - friend bool operator<=(const T& x, const U& y) { return !(x > y); } - friend bool operator>=(const T& x, const U& y) { return !(x < y); } + 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 !(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); } }; 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 !(y < x); } - friend bool operator>=(const T& x, const T& y) { return !(x < y); } + 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); } }; 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 !(x == y); } - friend bool operator!=(const T& y, const U& x) { return !(y == x); } + 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); } }; template > struct equality_comparable1 : B { - friend bool operator!=(const T& x, const T& y) { return !(x == y); } + friend bool operator!=(const T& x, const T& y) { return !static_cast(x == y); } }; // A macro which produces "name_2left" from "name". @@ -356,7 +358,7 @@ struct equivalent2 : B { friend bool operator==(const T& x, const U& y) { - return !(x < y) && !(x > y); + return !static_cast(x < y) && !static_cast(x > y); } }; @@ -365,7 +367,7 @@ struct equivalent1 : B { friend bool operator==(const T&x, const T&y) { - return !(x < y) && !(y < x); + return !static_cast(x < y) && !static_cast(y < x); } }; @@ -373,17 +375,17 @@ template > struct partially_ordered2 : B { friend bool operator<=(const T& x, const U& y) - { return (x < y) || (x == y); } + { return static_cast(x < y) || static_cast(x == y); } friend bool operator>=(const T& x, const U& y) - { return (x > y) || (x == y); } + { return static_cast(x > y) || 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 (y > x) || (y == x); } + { return static_cast(y > x) || static_cast(y == x); } friend bool operator>=(const U& x, const T& y) - { return (y < x) || (y == x); } + { return static_cast(y < x) || static_cast(y == x); } }; template > @@ -392,9 +394,9 @@ struct partially_ordered1 : B friend bool operator>(const T& x, const T& y) { return y < x; } friend bool operator<=(const T& x, const T& y) - { return (x < y) || (x == y); } + { return static_cast(x < y) || static_cast(x == y); } friend bool operator>=(const T& x, const T& y) - { return (y < x) || (x == y); } + { return static_cast(y < x) || static_cast(x == y); } }; // Combined operator classes (contributed by Daryle Walker) ----------------// diff --git a/operators_test.cpp b/operators_test.cpp index d42cb6a..dd40fbc 100644 --- a/operators_test.cpp +++ b/operators_test.cpp @@ -7,6 +7,7 @@ // See http://www.boost.org/libs/utility for documentation. // Revision History +// 03 Apr 08 Added convertible_to_bool (Daniel Frey) // 01 Oct 01 Added tests for "left" operators // and new grouped operators. (Helmut Zeisel) // 20 May 01 Output progress messages. Added tests for new operator @@ -43,6 +44,23 @@ namespace unsigned char true_value(unsigned char x) { return x; } unsigned short true_value(unsigned short x) { return x; } + // verify the minimum requirements for some operators + class convertible_to_bool + { + private: + bool _value; + + typedef bool convertible_to_bool::*unspecified_bool_type; + + void operator!() const; + + public: + convertible_to_bool( const bool value ) : _value( value ) {} + + operator unspecified_bool_type() const + { return _value ? &convertible_to_bool::_value : 0; } + }; + // The use of operators<> here tended to obscure // interactions with certain compiler bugs template @@ -54,8 +72,10 @@ namespace explicit Wrapped1( T v = T() ) : _value(v) {} T value() const { return _value; } - bool operator<(const Wrapped1& x) const { return _value < x._value; } - bool operator==(const Wrapped1& x) const { return _value == x._value; } + convertible_to_bool operator<(const Wrapped1& x) const + { return _value < x._value; } + convertible_to_bool operator==(const Wrapped1& x) const + { return _value == x._value; } Wrapped1& operator+=(const Wrapped1& x) { _value += x._value; return *this; } @@ -97,8 +117,10 @@ namespace explicit Wrapped2( T v = T() ) : _value(v) {} T value() const { return _value; } - bool operator<(const Wrapped2& x) const { return _value < x._value; } - bool operator==(const Wrapped2& x) const { return _value == x._value; } + convertible_to_bool operator<(const Wrapped2& x) const + { return _value < x._value; } + convertible_to_bool operator==(const Wrapped2& x) const + { return _value == x._value; } Wrapped2& operator+=(const Wrapped2& x) { _value += x._value; return *this; } @@ -123,9 +145,13 @@ namespace Wrapped2& operator++() { ++_value; return *this; } Wrapped2& operator--() { --_value; return *this; } - bool operator<(U u) const { return _value < u; } - bool operator>(U u) const { return _value > u; } - bool operator==(U u) const { return _value == u; } + convertible_to_bool operator<(U u) const + { return _value < u; } + convertible_to_bool operator>(U u) const + { return _value > u; } + convertible_to_bool operator==(U u) const + { return _value == u; } + Wrapped2& operator+=(U u) { _value += u; return *this; } Wrapped2& operator-=(U u) { _value -= u; return *this; } Wrapped2& operator*=(U u) { _value *= u; return *this; } @@ -153,7 +179,8 @@ namespace explicit Wrapped3( T v = T() ) : _value(v) {} T value() const { return _value; } - bool operator<(const Wrapped3& x) const { return _value < x._value; } + convertible_to_bool operator<(const Wrapped3& x) const + { return _value < x._value; } private: T _value; @@ -174,10 +201,13 @@ namespace explicit Wrapped4( T v = T() ) : _value(v) {} T value() const { return _value; } - bool operator<(const Wrapped4& x) const { return _value < x._value; } + convertible_to_bool operator<(const Wrapped4& x) const + { return _value < x._value; } - bool operator<(U u) const { return _value < u; } - bool operator>(U u) const { return _value > u; } + convertible_to_bool operator<(U u) const + { return _value < u; } + convertible_to_bool operator>(U u) const + { return _value > u; } private: T _value; @@ -198,11 +228,18 @@ namespace Wrapped5(U u) : _value(u) {} T value() const { return _value; } - bool operator<(const Wrapped5& x) const { return _value < x._value; } - bool operator<(U u) const { return _value < u; } - bool operator>(U u) const { return _value > u; } - bool operator==(const Wrapped5& u) const { return _value == u._value; } - bool operator==(U u) const { return _value == u; } + + convertible_to_bool operator<(const Wrapped5& x) const + { return _value < x._value; } + convertible_to_bool operator<(U u) const + { return _value < u; } + convertible_to_bool operator>(U u) const + { return _value > u; } + convertible_to_bool operator==(const Wrapped5& u) const + { return _value == u._value; } + convertible_to_bool operator==(U u) const + { return _value == u; } + Wrapped5& operator/=(const Wrapped5& u) { _value /= u._value; return *this;} Wrapped5& operator/=(U u) { _value /= u; return *this;} Wrapped5& operator*=(const Wrapped5& u) { _value *= u._value; return *this;} @@ -231,11 +268,18 @@ namespace Wrapped6(U u) : _value(u) {} T value() const { return _value; } - bool operator<(const Wrapped6& x) const { return _value < x._value; } - bool operator<(U u) const { return _value < u; } - bool operator>(U u) const { return _value > u; } - bool operator==(const Wrapped6& u) const { return _value == u._value; } - bool operator==(U u) const { return _value == u; } + + convertible_to_bool operator<(const Wrapped6& x) const + { return _value < x._value; } + convertible_to_bool operator<(U u) const + { return _value < u; } + convertible_to_bool operator>(U u) const + { return _value > u; } + convertible_to_bool operator==(const Wrapped6& u) const + { return _value == u._value; } + convertible_to_bool operator==(U u) const + { return _value == u; } + Wrapped6& operator%=(const Wrapped6& u) { _value %= u._value; return *this;} Wrapped6& operator%=(U u) { _value %= u; return *this;} Wrapped6& operator/=(const Wrapped6& u) { _value /= u._value; return *this;} @@ -276,10 +320,10 @@ namespace template void test_less_than_comparable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) { - BOOST_CHECK( (x1 < y1) == (x2 < y2) ); - BOOST_CHECK( (x1 <= y1) == (x2 <= y2) ); - BOOST_CHECK( (x1 >= y1) == (x2 >= y2) ); - BOOST_CHECK( (x1 > y1) == (x2 > y2) ); + BOOST_CHECK( static_cast(x1 < y1) == static_cast(x2 < y2) ); + BOOST_CHECK( static_cast(x1 <= y1) == static_cast(x2 <= y2) ); + BOOST_CHECK( static_cast(x1 >= y1) == static_cast(x2 >= y2) ); + BOOST_CHECK( static_cast(x1 > y1) == static_cast(x2 > y2) ); } template @@ -293,8 +337,8 @@ namespace template void test_equality_comparable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) { - BOOST_CHECK( (x1 == y1) == (x2 == y2) ); - BOOST_CHECK( (x1 != y1) == (x2 != y2) ); + BOOST_CHECK( static_cast(x1 == y1) == static_cast(x2 == y2) ); + BOOST_CHECK( static_cast(x1 != y1) == static_cast(x2 != y2) ); } template @@ -614,14 +658,14 @@ test_main( int , char * [] ) PRIVATE_EXPR_TEST( (i = i2), (i.value() == 2) ); - BOOST_CHECK( i2 == i ); - BOOST_CHECK( i1 != i2 ); - BOOST_CHECK( i1 < i2 ); - BOOST_CHECK( i1 <= i2 ); - BOOST_CHECK( i <= i2 ); - BOOST_CHECK( i2 > i1 ); - BOOST_CHECK( i2 >= i1 ); - BOOST_CHECK( i2 >= i ); + BOOST_CHECK( static_cast(i2 == i) ); + BOOST_CHECK( static_cast(i1 != i2) ); + BOOST_CHECK( static_cast(i1 < i2) ); + BOOST_CHECK( static_cast(i1 <= i2) ); + BOOST_CHECK( static_cast(i <= i2) ); + BOOST_CHECK( static_cast(i2 > i1) ); + BOOST_CHECK( static_cast(i2 >= i1) ); + BOOST_CHECK( static_cast(i2 >= i) ); PRIVATE_EXPR_TEST( (i = i1 + i2), (i.value() == 3) ); PRIVATE_EXPR_TEST( (i = i + i2), (i.value() == 5) ); @@ -653,78 +697,78 @@ test_main( int , char * [] ) PRIVATE_EXPR_TEST( (j = j2), (j.value() == 2) ); - BOOST_CHECK( j2 == j ); - BOOST_CHECK( 2 == j ); - BOOST_CHECK( j2 == 2 ); - BOOST_CHECK( j == j2 ); - BOOST_CHECK( j1 != j2 ); - BOOST_CHECK( j1 != 2 ); - BOOST_CHECK( 1 != j2 ); - BOOST_CHECK( j1 < j2 ); - BOOST_CHECK( 1 < j2 ); - BOOST_CHECK( j1 < 2 ); - BOOST_CHECK( j1 <= j2 ); - BOOST_CHECK( 1 <= j2 ); - BOOST_CHECK( j1 <= j ); - BOOST_CHECK( j <= j2 ); - BOOST_CHECK( 2 <= j2 ); - BOOST_CHECK( j <= 2 ); - BOOST_CHECK( j2 > j1 ); - BOOST_CHECK( 2 > j1 ); - BOOST_CHECK( j2 > 1 ); - BOOST_CHECK( j2 >= j1 ); - BOOST_CHECK( 2 >= j1 ); - BOOST_CHECK( j2 >= 1 ); - BOOST_CHECK( j2 >= j ); - BOOST_CHECK( 2 >= j ); - BOOST_CHECK( j2 >= 2 ); + BOOST_CHECK( static_cast(j2 == j) ); + BOOST_CHECK( static_cast(2 == j) ); + BOOST_CHECK( static_cast(j2 == 2) ); + BOOST_CHECK( static_cast(j == j2) ); + BOOST_CHECK( static_cast(j1 != j2) ); + BOOST_CHECK( static_cast(j1 != 2) ); + BOOST_CHECK( static_cast(1 != j2) ); + BOOST_CHECK( static_cast(j1 < j2) ); + BOOST_CHECK( static_cast(1 < j2) ); + BOOST_CHECK( static_cast(j1 < 2) ); + BOOST_CHECK( static_cast(j1 <= j2) ); + BOOST_CHECK( static_cast(1 <= j2) ); + BOOST_CHECK( static_cast(j1 <= j) ); + BOOST_CHECK( static_cast(j <= j2) ); + BOOST_CHECK( static_cast(2 <= j2) ); + BOOST_CHECK( static_cast(j <= 2) ); + BOOST_CHECK( static_cast(j2 > j1) ); + BOOST_CHECK( static_cast(2 > j1) ); + BOOST_CHECK( static_cast(j2 > 1) ); + BOOST_CHECK( static_cast(j2 >= j1) ); + BOOST_CHECK( static_cast(2 >= j1) ); + BOOST_CHECK( static_cast(j2 >= 1) ); + BOOST_CHECK( static_cast(j2 >= j) ); + BOOST_CHECK( static_cast(2 >= j) ); + BOOST_CHECK( static_cast(j2 >= 2) ); - BOOST_CHECK( (j1 + 2) == 3 ); - BOOST_CHECK( (1 + j2) == 3 ); + BOOST_CHECK( static_cast((j1 + 2) == 3) ); + BOOST_CHECK( static_cast((1 + j2) == 3) ); PRIVATE_EXPR_TEST( (j = j1 + j2), (j.value() == 3) ); - BOOST_CHECK( (j + 2) == 5 ); - BOOST_CHECK( (3 + j2) == 5 ); + BOOST_CHECK( static_cast((j + 2) == 5) ); + BOOST_CHECK( static_cast((3 + j2) == 5) ); PRIVATE_EXPR_TEST( (j = j + j2), (j.value() == 5) ); - BOOST_CHECK( (j - 1) == 4 ); + BOOST_CHECK( static_cast((j - 1) == 4) ); PRIVATE_EXPR_TEST( (j = j - j1), (j.value() == 4) ); - BOOST_CHECK( (j * 2) == 8 ); - BOOST_CHECK( (4 * j2) == 8 ); + BOOST_CHECK( static_cast((j * 2) == 8) ); + BOOST_CHECK( static_cast((4 * j2) == 8) ); PRIVATE_EXPR_TEST( (j = j * j2), (j.value() == 8) ); - BOOST_CHECK( (j / 2) == 4 ); + BOOST_CHECK( static_cast((j / 2) == 4) ); PRIVATE_EXPR_TEST( (j = j / j2), (j.value() == 4) ); - BOOST_CHECK( (j % 3) == 1 ); + BOOST_CHECK( static_cast((j % 3) == 1) ); PRIVATE_EXPR_TEST( (j = j % ( j - j1 )), (j.value() == 1) ); PRIVATE_EXPR_TEST( (j = j2 + j2), (j.value() == 4) ); - BOOST_CHECK( (1 | j2 | j) == 7 ); - BOOST_CHECK( (j1 | 2 | j) == 7 ); - BOOST_CHECK( (j1 | j2 | 4) == 7 ); + BOOST_CHECK( static_cast((1 | j2 | j) == 7) ); + BOOST_CHECK( static_cast((j1 | 2 | j) == 7) ); + BOOST_CHECK( static_cast((j1 | j2 | 4) == 7) ); PRIVATE_EXPR_TEST( (j = j1 | j2 | j), (j.value() == 7) ); - BOOST_CHECK( (7 & j2) == 2 ); - BOOST_CHECK( (j & 2) == 2 ); + BOOST_CHECK( static_cast((7 & j2) == 2) ); + BOOST_CHECK( static_cast((j & 2) == 2) ); PRIVATE_EXPR_TEST( (j = j & j2), (j.value() == 2) ); PRIVATE_EXPR_TEST( (j = j | j1), (j.value() == 3) ); - BOOST_CHECK( (3 ^ j1) == 2 ); - BOOST_CHECK( (j ^ 1) == 2 ); + BOOST_CHECK( static_cast((3 ^ j1) == 2) ); + BOOST_CHECK( static_cast((j ^ 1) == 2) ); PRIVATE_EXPR_TEST( (j = j ^ j1), (j.value() == 2) ); PRIVATE_EXPR_TEST( (j = ( j + j1 ) * ( j2 | j1 )), (j.value() == 9) ); - BOOST_CHECK( (j1 << 2) == 4 ); - BOOST_CHECK( (j2 << 1) == 4 ); + BOOST_CHECK( static_cast((j1 << 2) == 4) ); + BOOST_CHECK( static_cast((j2 << 1) == 4) ); PRIVATE_EXPR_TEST( (j = j1 << j2), (j.value() == 4) ); - BOOST_CHECK( (j >> 2) == 1 ); - BOOST_CHECK( (j2 >> 1) == 1 ); + BOOST_CHECK( static_cast((j >> 2) == 1) ); + BOOST_CHECK( static_cast((j2 >> 1) == 1) ); PRIVATE_EXPR_TEST( (j = j2 >> j1), (j.value() == 1) ); cout << "Performed tests on MyLong objects.\n"; @@ -741,14 +785,14 @@ test_main( int , char * [] ) PRIVATE_EXPR_TEST( (k = k2), (k.value() == 2) ); - BOOST_CHECK( k2 == k ); - BOOST_CHECK( k1 != k2 ); - BOOST_CHECK( k1 < k2 ); - BOOST_CHECK( k1 <= k2 ); - BOOST_CHECK( k <= k2 ); - BOOST_CHECK( k2 > k1 ); - BOOST_CHECK( k2 >= k1 ); - BOOST_CHECK( k2 >= k ); + BOOST_CHECK( static_cast(k2 == k) ); + BOOST_CHECK( static_cast(k1 != k2) ); + BOOST_CHECK( static_cast(k1 < k2) ); + BOOST_CHECK( static_cast(k1 <= k2) ); + BOOST_CHECK( static_cast(k <= k2) ); + BOOST_CHECK( static_cast(k2 > k1) ); + BOOST_CHECK( static_cast(k2 >= k1) ); + BOOST_CHECK( static_cast(k2 >= k) ); cout << "Performed tests on MyChar objects.\n"; @@ -764,31 +808,31 @@ test_main( int , char * [] ) PRIVATE_EXPR_TEST( (l = l2), (l.value() == 2) ); - BOOST_CHECK( l2 == l ); - BOOST_CHECK( 2 == l ); - BOOST_CHECK( l2 == 2 ); - BOOST_CHECK( l == l2 ); - BOOST_CHECK( l1 != l2 ); - BOOST_CHECK( l1 != 2 ); - BOOST_CHECK( 1 != l2 ); - BOOST_CHECK( l1 < l2 ); - BOOST_CHECK( 1 < l2 ); - BOOST_CHECK( l1 < 2 ); - BOOST_CHECK( l1 <= l2 ); - BOOST_CHECK( 1 <= l2 ); - BOOST_CHECK( l1 <= l ); - BOOST_CHECK( l <= l2 ); - BOOST_CHECK( 2 <= l2 ); - BOOST_CHECK( l <= 2 ); - BOOST_CHECK( l2 > l1 ); - BOOST_CHECK( 2 > l1 ); - BOOST_CHECK( l2 > 1 ); - BOOST_CHECK( l2 >= l1 ); - BOOST_CHECK( 2 >= l1 ); - BOOST_CHECK( l2 >= 1 ); - BOOST_CHECK( l2 >= l ); - BOOST_CHECK( 2 >= l ); - BOOST_CHECK( l2 >= 2 ); + BOOST_CHECK( static_cast(l2 == l) ); + BOOST_CHECK( static_cast(2 == l) ); + BOOST_CHECK( static_cast(l2 == 2) ); + BOOST_CHECK( static_cast(l == l2) ); + BOOST_CHECK( static_cast(l1 != l2) ); + BOOST_CHECK( static_cast(l1 != 2) ); + BOOST_CHECK( static_cast(1 != l2) ); + BOOST_CHECK( static_cast(l1 < l2) ); + BOOST_CHECK( static_cast(1 < l2) ); + BOOST_CHECK( static_cast(l1 < 2) ); + BOOST_CHECK( static_cast(l1 <= l2) ); + BOOST_CHECK( static_cast(1 <= l2) ); + BOOST_CHECK( static_cast(l1 <= l) ); + BOOST_CHECK( static_cast(l <= l2) ); + BOOST_CHECK( static_cast(2 <= l2) ); + BOOST_CHECK( static_cast(l <= 2) ); + BOOST_CHECK( static_cast(l2 > l1) ); + BOOST_CHECK( static_cast(2 > l1) ); + BOOST_CHECK( static_cast(l2 > 1) ); + BOOST_CHECK( static_cast(l2 >= l1) ); + BOOST_CHECK( static_cast(2 >= l1) ); + BOOST_CHECK( static_cast(l2 >= 1) ); + BOOST_CHECK( static_cast(l2 >= l) ); + BOOST_CHECK( static_cast(2 >= l) ); + BOOST_CHECK( static_cast(l2 >= 2) ); cout << "Performed tests on MyShort objects.\n"; @@ -807,37 +851,37 @@ test_main( int , char * [] ) PRIVATE_EXPR_TEST( (di = di2), (di.value() == 2) ); - BOOST_CHECK( di2 == di ); - BOOST_CHECK( 2 == di ); - BOOST_CHECK( di == 2 ); - BOOST_CHECK( di1 < di2 ); - BOOST_CHECK( 1 < di2 ); - BOOST_CHECK( di1 <= di2 ); - BOOST_CHECK( 1 <= di2 ); - BOOST_CHECK( di2 > di1 ); - BOOST_CHECK( di2 > 1 ); - BOOST_CHECK( di2 >= di1 ); - BOOST_CHECK( di2 >= 1 ); - BOOST_CHECK( di1 / di2 == half ); - BOOST_CHECK( di1 / 2 == half ); - BOOST_CHECK( 1 / di2 == half ); - PRIVATE_EXPR_TEST( (tmp=di1), ((tmp/=2) == half) ); - PRIVATE_EXPR_TEST( (tmp=di1), ((tmp/=di2) == half) ); - BOOST_CHECK( di1 * di2 == di2 ); - BOOST_CHECK( di1 * 2 == di2 ); - BOOST_CHECK( 1 * di2 == di2 ); - PRIVATE_EXPR_TEST( (tmp=di1), ((tmp*=2) == di2) ); - PRIVATE_EXPR_TEST( (tmp=di1), ((tmp*=di2) == di2) ); - BOOST_CHECK( di2 - di1 == di1 ); - BOOST_CHECK( di2 - 1 == di1 ); - BOOST_CHECK( 2 - di1 == di1 ); - PRIVATE_EXPR_TEST( (tmp=di2), ((tmp-=1) == di1) ); - PRIVATE_EXPR_TEST( (tmp=di2), ((tmp-=di1) == di1) ); - BOOST_CHECK( di1 + di1 == di2 ); - BOOST_CHECK( di1 + 1 == di2 ); - BOOST_CHECK( 1 + di1 == di2 ); - PRIVATE_EXPR_TEST( (tmp=di1), ((tmp+=1) == di2) ); - PRIVATE_EXPR_TEST( (tmp=di1), ((tmp+=di1) == di2) ); + BOOST_CHECK( static_cast(di2 == di) ); + BOOST_CHECK( static_cast(2 == di) ); + BOOST_CHECK( static_cast(di == 2) ); + BOOST_CHECK( static_cast(di1 < di2) ); + BOOST_CHECK( static_cast(1 < di2) ); + BOOST_CHECK( static_cast(di1 <= di2) ); + BOOST_CHECK( static_cast(1 <= di2) ); + BOOST_CHECK( static_cast(di2 > di1) ); + BOOST_CHECK( static_cast(di2 > 1) ); + BOOST_CHECK( static_cast(di2 >= di1) ); + BOOST_CHECK( static_cast(di2 >= 1) ); + BOOST_CHECK( static_cast(di1 / di2 == half) ); + BOOST_CHECK( static_cast(di1 / 2 == half) ); + BOOST_CHECK( static_cast(1 / di2 == half) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp/=2) == half) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp/=di2) == half) ); + BOOST_CHECK( static_cast(di1 * di2 == di2) ); + BOOST_CHECK( static_cast(di1 * 2 == di2) ); + BOOST_CHECK( static_cast(1 * di2 == di2) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp*=2) == di2) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp*=di2) == di2) ); + BOOST_CHECK( static_cast(di2 - di1 == di1) ); + BOOST_CHECK( static_cast(di2 - 1 == di1) ); + BOOST_CHECK( static_cast(2 - di1 == di1) ); + PRIVATE_EXPR_TEST( (tmp=di2), static_cast((tmp-=1) == di1) ); + PRIVATE_EXPR_TEST( (tmp=di2), static_cast((tmp-=di1) == di1) ); + BOOST_CHECK( static_cast(di1 + di1 == di2) ); + BOOST_CHECK( static_cast(di1 + 1 == di2) ); + BOOST_CHECK( static_cast(1 + di1 == di2) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp+=1) == di2) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp+=di1) == di2) ); cout << "Performed tests on MyDoubleInt objects.\n"; @@ -854,42 +898,42 @@ test_main( int , char * [] ) PRIVATE_EXPR_TEST( (li = li2), (li.value() == 2) ); - BOOST_CHECK( li2 == li ); - BOOST_CHECK( 2 == li ); - BOOST_CHECK( li == 2 ); - BOOST_CHECK( li1 < li2 ); - BOOST_CHECK( 1 < li2 ); - BOOST_CHECK( li1 <= li2 ); - BOOST_CHECK( 1 <= li2 ); - BOOST_CHECK( li2 > li1 ); - BOOST_CHECK( li2 > 1 ); - BOOST_CHECK( li2 >= li1 ); - BOOST_CHECK( li2 >= 1 ); - BOOST_CHECK( li1 % li2 == li1 ); - BOOST_CHECK( li1 % 2 == li1 ); - BOOST_CHECK( 1 % li2 == li1 ); - PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2%=2) == li1) ); - PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2%=li2) == li1) ); - BOOST_CHECK( li1 / li2 == 0 ); - BOOST_CHECK( li1 / 2 == 0 ); - BOOST_CHECK( 1 / li2 == 0 ); - PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2/=2) == 0) ); - PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2/=li2) == 0) ); - BOOST_CHECK( li1 * li2 == li2 ); - BOOST_CHECK( li1 * 2 == li2 ); - BOOST_CHECK( 1 * li2 == li2 ); - PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2*=2) == li2) ); - PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2*=li2) == li2) ); - BOOST_CHECK( li2 - li1 == li1 ); - BOOST_CHECK( li2 - 1 == li1 ); - BOOST_CHECK( 2 - li1 == li1 ); - PRIVATE_EXPR_TEST( (tmp2=li2), ((tmp2-=1) == li1) ); - PRIVATE_EXPR_TEST( (tmp2=li2), ((tmp2-=li1) == li1) ); - BOOST_CHECK( li1 + li1 == li2 ); - BOOST_CHECK( li1 + 1 == li2 ); - BOOST_CHECK( 1 + li1 == li2 ); - PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2+=1) == li2) ); - PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2+=li1) == li2) ); + BOOST_CHECK( static_cast(li2 == li) ); + BOOST_CHECK( static_cast(2 == li) ); + BOOST_CHECK( static_cast(li == 2) ); + BOOST_CHECK( static_cast(li1 < li2) ); + BOOST_CHECK( static_cast(1 < li2) ); + BOOST_CHECK( static_cast(li1 <= li2) ); + BOOST_CHECK( static_cast(1 <= li2) ); + BOOST_CHECK( static_cast(li2 > li1) ); + BOOST_CHECK( static_cast(li2 > 1) ); + BOOST_CHECK( static_cast(li2 >= li1) ); + BOOST_CHECK( static_cast(li2 >= 1) ); + BOOST_CHECK( static_cast(li1 % li2 == li1) ); + BOOST_CHECK( static_cast(li1 % 2 == li1) ); + BOOST_CHECK( static_cast(1 % li2 == li1) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2%=2) == li1) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2%=li2) == li1) ); + BOOST_CHECK( static_cast(li1 / li2 == 0) ); + BOOST_CHECK( static_cast(li1 / 2 == 0) ); + BOOST_CHECK( static_cast(1 / li2 == 0) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2/=2) == 0) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2/=li2) == 0) ); + BOOST_CHECK( static_cast(li1 * li2 == li2) ); + BOOST_CHECK( static_cast(li1 * 2 == li2) ); + BOOST_CHECK( static_cast(1 * li2 == li2) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2*=2) == li2) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2*=li2) == li2) ); + BOOST_CHECK( static_cast(li2 - li1 == li1) ); + BOOST_CHECK( static_cast(li2 - 1 == li1) ); + BOOST_CHECK( static_cast(2 - li1 == li1) ); + PRIVATE_EXPR_TEST( (tmp2=li2), static_cast((tmp2-=1) == li1) ); + PRIVATE_EXPR_TEST( (tmp2=li2), static_cast((tmp2-=li1) == li1) ); + BOOST_CHECK( static_cast(li1 + li1 == li2) ); + BOOST_CHECK( static_cast(li1 + 1 == li2) ); + BOOST_CHECK( static_cast(1 + li1 == li2) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2+=1) == li2) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2+=li1) == li2) ); cout << "Performed tests on MyLongInt objects.\n"; From bafe37fdab1a22f552728f59fc6c00105057ba2f Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Tue, 15 Apr 2008 21:13:24 +0000 Subject: [PATCH 02/30] Boost Exception header compilation tests added. [SVN r44442] --- include/boost/exception.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/exception.hpp b/include/boost/exception.hpp index 6a49ab8..aca1409 100644 --- a/include/boost/exception.hpp +++ b/include/boost/exception.hpp @@ -7,7 +7,7 @@ #define UUID_1D94A7C6054E11DB9804B622A1EF5492 #include -#include +#include #include #endif From a5b85eda07d936b497dd519a8dbfe8339f6d9d2d Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 21 Apr 2008 21:42:29 +0000 Subject: [PATCH 03/30] Fix #1846. [SVN r44705] --- include/boost/utility/addressof.hpp | 43 ++++++++++++++++------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index 7629488..8e0a586 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -1,6 +1,7 @@ // Copyright (C) 2002 Brad King (brad.king@kitware.com) // Douglas Gregor (gregod@cs.rpi.edu) -// Peter Dimov +// +// Copyright (C) 2002, 2008 Peter Dimov // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -14,27 +15,31 @@ # include # include -namespace boost { - -// Do not make addressof() inline. Breaks MSVC 7. (Peter Dimov) - -// VC7 strips const from nested classes unless we add indirection here -# if BOOST_WORKAROUND(BOOST_MSVC, == 1300) - -template struct _addp +namespace boost { - typedef T * type; + +namespace detail +{ + +template struct addressof_impl +{ + static inline T * f( T & v, long ) + { + return reinterpret_cast( + &const_cast(reinterpret_cast(v))); + } + + static inline T * f( T * v, int ) + { + return v; + } }; - -template typename _addp::type -# else -template T* -# endif -addressof(T& v) +} // namespace detail + +template T * addressof( T & v ) { - return reinterpret_cast( - &const_cast(reinterpret_cast(v))); + return boost::detail::addressof_impl::f( v, 0 ); } // Borland doesn't like casting an array reference to a char reference @@ -53,6 +58,6 @@ const T (*addressof(const T (&t)[N]))[N] } # endif -} +} // namespace boost #endif // BOOST_UTILITY_ADDRESSOF_HPP From f1c86c35c43c6a625c2fbd0fe350fec39ab4d829 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 27 Apr 2008 07:39:49 +0000 Subject: [PATCH 04/30] Merge in documentation fixes. Apart from the change to optional's documenation Jamfile, which I included by mistake. Fixes #1659, #1661, #1684, #1685, 1687, #1690, #1801 I wrote about this at: http://lists.boost.org/Archives/boost/2008/04/136405.php Merged revisions 44585-44806 via svnmerge from https://svn.boost.org/svn/boost/branches/doc ........ r44585 | danieljames | 2008-04-19 16:25:27 +0100 (Sat, 19 Apr 2008) | 2 lines Fix broken link to vacpp in bjam docs. Refs #1512 ........ r44586 | danieljames | 2008-04-19 16:27:36 +0100 (Sat, 19 Apr 2008) | 2 lines Fix broken link to bcpp in bjam docs. Refs #1513 ........ r44587 | danieljames | 2008-04-19 16:33:58 +0100 (Sat, 19 Apr 2008) | 2 lines DateTime documentation - Fix a link to the serialization library. Refs #1659 ........ r44588 | danieljames | 2008-04-19 16:35:36 +0100 (Sat, 19 Apr 2008) | 2 lines Fix some links in interprocess & intrusive. Refs #1661 ........ r44589 | danieljames | 2008-04-19 16:37:39 +0100 (Sat, 19 Apr 2008) | 2 lines Fix some links in the python docs. Refs #1684. ........ r44590 | danieljames | 2008-04-19 16:38:29 +0100 (Sat, 19 Apr 2008) | 2 lines Work around a quickbook bug which is affecting the python docs. Refs #1684. ........ r44591 | danieljames | 2008-04-19 16:39:34 +0100 (Sat, 19 Apr 2008) | 2 lines Fix a broken link in the numeric conversion docs. Refs #1685 ........ r44592 | danieljames | 2008-04-19 16:40:45 +0100 (Sat, 19 Apr 2008) | 2 lines Fix some links in the optional docs. Refs #1687 ........ r44593 | danieljames | 2008-04-19 16:42:09 +0100 (Sat, 19 Apr 2008) | 2 lines Fix link to the hash documentation from bimap. Refs #1690 ........ r44599 | danieljames | 2008-04-19 18:07:33 +0100 (Sat, 19 Apr 2008) | 2 lines Fix a typo in the format library. Refs #1801 ........ r44600 | danieljames | 2008-04-19 19:20:59 +0100 (Sat, 19 Apr 2008) | 1 line Initialise svnmerge. ........ r44641 | danieljames | 2008-04-20 18:59:47 +0100 (Sun, 20 Apr 2008) | 2 lines Fix the lincense url in shared container iterator documentation. ........ r44642 | danieljames | 2008-04-20 19:00:00 +0100 (Sun, 20 Apr 2008) | 2 lines Fix image link in the mpi documentation. ........ r44643 | danieljames | 2008-04-20 19:00:11 +0100 (Sun, 20 Apr 2008) | 2 lines Fix a typo in the spirit docs. ........ r44644 | danieljames | 2008-04-20 19:00:23 +0100 (Sun, 20 Apr 2008) | 2 lines Escape the slash so that quickbook doesn't think it the start of an italic section, and mess up the link. Refs #1844 ........ r44647 | danieljames | 2008-04-20 19:39:47 +0100 (Sun, 20 Apr 2008) | 2 lines Fix another typo in spirit docs. ........ [SVN r44807] --- shared_container_iterator.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared_container_iterator.html b/shared_container_iterator.html index dfef648..ed149b5 100644 --- a/shared_container_iterator.html +++ b/shared_container_iterator.html @@ -315,7 +315,7 @@ Last modified: Mon Aug 11 11:27:03 EST 2003

© Copyright 2003 The Trustees of Indiana University. Use, modification and distribution is subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at - http:www.boost.org/LICENSE_1_0.txt)

+ http://www.boost.org/LICENSE_1_0.txt)

From ad0bcf4a00670df71a2ed0e10d98a51c954863ea Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 9 May 2008 22:08:46 +0000 Subject: [PATCH 05/30] result_of implementation that makes use of C++0x decltype, from Daniel Walker. Fixes #862. [SVN r45256] --- .../utility/detail/result_of_iterate.hpp | 42 ++++++ include/boost/utility/result_of.hpp | 4 + test/result_of_test.cpp | 127 ++++++++++++++++-- utility.htm | 8 +- 4 files changed, 169 insertions(+), 12 deletions(-) diff --git a/include/boost/utility/detail/result_of_iterate.hpp b/include/boost/utility/detail/result_of_iterate.hpp index 41616c3..6f1b2b1 100644 --- a/include/boost/utility/detail/result_of_iterate.hpp +++ b/include/boost/utility/detail/result_of_iterate.hpp @@ -10,6 +10,46 @@ # error Boost result_of - do not include this file! #endif +#if defined(BOOST_HAS_DECLTYPE) + +// As of N2588, C++0x result_of only supports function call +// expressions of the form f(x). This precludes support for member +// function pointers, which are invoked with expressions of the form +// o->*f(x). This implementation supports both. +template +struct result_of + : mpl::if_< + mpl::or_< is_pointer, is_member_function_pointer > + , detail::result_of_impl< + F, F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false + > + , detail::result_of_decltype_impl< + F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)) + > + >::type +{}; + +namespace detail { + +# define BOOST_RESULT_OF_STATIC_MEMBERS(z, n, _) \ + static T ## n t ## n; \ + /**/ + +template +class result_of_decltype_impl +{ + static F f; + BOOST_PP_REPEAT(BOOST_PP_ITERATION(), BOOST_RESULT_OF_STATIC_MEMBERS, _) +public: + typedef decltype(f(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),t))) type; +}; + +} // namespace detail + +#else // defined(BOOST_HAS_DECLTYPE) + // CWPro8 requires an argument in a function type specialization #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3002)) && BOOST_PP_ITERATION() == 0 # define BOOST_RESULT_OF_ARGS void @@ -26,6 +66,8 @@ struct result_of #undef BOOST_RESULT_OF_ARGS +#endif // defined(BOOST_HAS_DECLTYPE) + #if BOOST_PP_ITERATION() >= 1 namespace detail { diff --git a/include/boost/utility/result_of.hpp b/include/boost/utility/result_of.hpp index a5bac6f..07306d6 100644 --- a/include/boost/utility/result_of.hpp +++ b/include/boost/utility/result_of.hpp @@ -18,6 +18,9 @@ #include #include #include +#include +#include +#include #ifndef BOOST_RESULT_OF_NUM_ARGS # define BOOST_RESULT_OF_NUM_ARGS 10 @@ -33,6 +36,7 @@ namespace detail { BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type) template struct result_of_impl; +template struct result_of_decltype_impl; template struct result_of_void_impl diff --git a/test/result_of_test.cpp b/test/result_of_test.cpp index 10f3410..c6e91ea 100644 --- a/test/result_of_test.cpp +++ b/test/result_of_test.cpp @@ -11,35 +11,101 @@ #include #include -struct int_result_type { typedef int result_type; }; +struct int_result_type +{ + typedef int result_type; + result_type operator()(float); +}; struct int_result_of { template struct result { typedef int type; }; + result::type operator()(double); + result::type operator()(double) const; + result::type operator()(); + result::type operator()() volatile; }; -struct int_result_type_and_float_result_of +struct int_result_type_and_float_result_of_and_char_return { typedef int result_type; template struct result { typedef float type; }; + char operator()(char); }; template -struct int_result_type_template { typedef int result_type; }; +struct int_result_type_template +{ + typedef int result_type; + result_type operator()(float); +}; template struct int_result_of_template { template struct result; template struct result { typedef int type; }; + typename result(double)>::type operator()(double); + typename result(double)>::type operator()(double) const; + typename result(double)>::type operator()(); + typename result(double)>::type operator()() volatile; }; template -struct int_result_type_and_float_result_of_template +struct int_result_type_and_float_result_of_and_char_return_template { typedef int result_type; template struct result; template struct result { typedef float type; }; + char operator()(char); +}; + +struct result_of_member_function_template +{ + template struct result; + + template struct result { typedef That type; }; + template typename result::type operator()(T); + + template struct result { typedef const That type; }; + template typename result::type operator()(T) const; + + template struct result { typedef volatile That type; }; + template typename result::type operator()(T) volatile; + + template struct result { typedef const volatile That type; }; + template typename result::type operator()(T) const volatile; + + template struct result { typedef That & type; }; + template typename result::type operator()(T &, T); + + template struct result { typedef That const & type; }; + template typename result::type operator()(T const &, T); + + template struct result { typedef That volatile & type; }; + template typename result::type operator()(T volatile &, T); + + template struct result { typedef That const volatile & type; }; + template typename result::type operator()(T const volatile &, T); +}; + +struct no_result_type_or_result_of +{ + int operator()(double); + short operator()(double) const; + unsigned int operator()(); + unsigned short operator()() volatile; + const unsigned short operator()() const volatile; +}; + +template +struct no_result_type_or_result_of_template +{ + int operator()(double); + short operator()(double) const; + unsigned int operator()(); + unsigned short operator()() volatile; + const unsigned short operator()() const volatile; }; struct X {}; @@ -60,16 +126,37 @@ int main() BOOST_STATIC_ASSERT((is_same::type, int>::value)); BOOST_STATIC_ASSERT((is_same::type, int>::value)); - BOOST_STATIC_ASSERT((is_same::type, void>::value)); BOOST_STATIC_ASSERT((is_same::type, int>::value)); - BOOST_STATIC_ASSERT((is_same::type, void>::value)); - BOOST_STATIC_ASSERT((is_same::type, int>::value)); BOOST_STATIC_ASSERT((is_same(float)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same(double)>::type, int>::value)); - BOOST_STATIC_ASSERT((is_same(void)>::type, void>::value)); BOOST_STATIC_ASSERT((is_same(double)>::type, int>::value)); + + // Prior to decltype, result_of could not deduce the return type + // nullary function objects unless they exposed a result_type. +#if defined(BOOST_HAS_DECLTYPE) + BOOST_STATIC_ASSERT((is_same::type, int>::value)); + BOOST_STATIC_ASSERT((is_same::type, int>::value)); + BOOST_STATIC_ASSERT((is_same(void)>::type, int>::value)); + BOOST_STATIC_ASSERT((is_same(void)>::type, int>::value)); +#else + BOOST_STATIC_ASSERT((is_same::type, void>::value)); + BOOST_STATIC_ASSERT((is_same::type, void>::value)); + BOOST_STATIC_ASSERT((is_same(void)>::type, void>::value)); BOOST_STATIC_ASSERT((is_same(void)>::type, void>::value)); - BOOST_STATIC_ASSERT((is_same(char)>::type, int>::value)); +#endif + + // Prior to decltype, result_of ignored a nested result<> if + // result_type was defined. After decltype, result_of deduces the + // actual return type of the function object, ignoring both + // result<> and result_type. +#if defined(BOOST_HAS_DECLTYPE) + BOOST_STATIC_ASSERT((is_same::type, char>::value)); + BOOST_STATIC_ASSERT((is_same(char)>::type, char>::value)); +#else + BOOST_STATIC_ASSERT((is_same::type, int>::value)); + BOOST_STATIC_ASSERT((is_same(char)>::type, int>::value)); +#endif + BOOST_STATIC_ASSERT((is_same::type, int>::value)); BOOST_STATIC_ASSERT((is_same::type, int>::value)); BOOST_STATIC_ASSERT((is_same::type, int>::value)); @@ -81,5 +168,27 @@ int main() BOOST_STATIC_ASSERT((is_same::type, int>::value)); BOOST_STATIC_ASSERT((is_same::type, int>::value)); + BOOST_STATIC_ASSERT((is_same::type, double>::value)); + BOOST_STATIC_ASSERT((is_same::type, const double>::value)); + BOOST_STATIC_ASSERT((is_same::type, volatile double>::value)); + BOOST_STATIC_ASSERT((is_same::type, const volatile double>::value)); + BOOST_STATIC_ASSERT((is_same::type, int &>::value)); + BOOST_STATIC_ASSERT((is_same::type, int const &>::value)); + BOOST_STATIC_ASSERT((is_same::type, int volatile &>::value)); + BOOST_STATIC_ASSERT((is_same::type, int const volatile &>::value)); + +#if defined(BOOST_HAS_DECLTYPE) + BOOST_STATIC_ASSERT((is_same::type, int>::value)); + BOOST_STATIC_ASSERT((is_same::type, unsigned int>::value)); + BOOST_STATIC_ASSERT((is_same::type, short>::value)); + BOOST_STATIC_ASSERT((is_same::type, unsigned short>::value)); + BOOST_STATIC_ASSERT((is_same::type, const unsigned short>::value)); + BOOST_STATIC_ASSERT((is_same(double)>::type, int>::value)); + BOOST_STATIC_ASSERT((is_same(void)>::type, unsigned int>::value)); + BOOST_STATIC_ASSERT((is_same(double)>::type, short>::value)); + BOOST_STATIC_ASSERT((is_same(void)>::type, unsigned short>::value)); + BOOST_STATIC_ASSERT((is_same(void)>::type, const unsigned short>::value)); +#endif + return 0; } diff --git a/utility.htm b/utility.htm index 9514188..1102d47 100644 --- a/utility.htm +++ b/utility.htm @@ -152,11 +152,13 @@ void f() { ...,tN). The implementation permits the type F to be a function pointer, function reference, member function pointer, or class - type. When F is a class type with a - member type result_type, + type.

If your compiler does not support + decltype, then when F is a + class type with a member type result_type, result_of<F(T1, T2, ..., TN)> is - F::result_type. Otherwise, + F::result_type. When F + does not contain result_type, result_of<F(T1, T2, ..., TN)> is F::result<F(T1, T2, ..., TN)>::type when From 8efae71f4aa6f6721daa0fc7084869129305463b Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 23 May 2008 16:46:43 +0000 Subject: [PATCH 06/30] Changed boost::initialized_value from a class to an instance, to make its use more convenient, as discussed with Fernando. [SVN r45685] --- include/boost/utility/value_init.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/boost/utility/value_init.hpp b/include/boost/utility/value_init.hpp index 60879cf..67127c0 100644 --- a/include/boost/utility/value_init.hpp +++ b/include/boost/utility/value_init.hpp @@ -5,7 +5,8 @@ // http://www.boost.org/LICENSE_1_0.txt) // // 21 Ago 2002 (Created) Fernando Cacciola -// 18 Feb 2008 (Worked around compiler bugs, added initialized_value) Fernando Cacciola, Niels Dekker +// 24 Dec 2007 (Refactored and worked around various compiler bugs) Fernando Cacciola, Niels Dekker +// 23 May 2008 (Fixed operator= const issue, added initialized_value) Niels Dekker, Fernando Cacciola // #ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP #define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP @@ -110,7 +111,7 @@ T& get ( value_initialized& x ) } -class initialized_value +class initialized_value_t { public : @@ -120,6 +121,8 @@ class initialized_value } }; +initialized_value_t const initialized_value = {} ; + } // namespace boost From 67f3ca090aeea6fae4b41aa06c4838e4dca5e131 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 23 May 2008 16:48:10 +0000 Subject: [PATCH 07/30] Fixed value_init test + doc, according to change of boost::initialized_value, revision [45685] [SVN r45686] --- value_init.htm | 29 +++++++++++++++++------------ value_init_test.cpp | 5 +++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/value_init.htm b/value_init.htm index c97a0eb..6bbfcbc 100644 --- a/value_init.htm +++ b/value_init.htm @@ -28,12 +28,12 @@

-
Types
+
Types and objects
Acknowledgements
@@ -53,7 +53,7 @@ union and class types. Moreover, value_initialized offers a workaround to various compiler issues regarding value-initialization. -Furthermore a convenience class, initialized_value is provided, +Furthermore, a const object, initialized_value is provided, to avoid repeating the type name when retrieving the value from a value_initialized<T> object.
@@ -123,12 +123,12 @@ constructed by the following declaration:

-The convenience class initialized_value +The const object initialized_value allows value-initializing a variable as follows:

-  T var = initialized_value();
+  T var = initialized_value ;
 
-This form of initialization is also very similar to T4 var4 = T4(), +This form of initialization is semantically equivalent to T4 var4 = T4(), but robust against the aforementioned compiler issues.

@@ -249,7 +249,7 @@ offer a workaround to these issues: value_initialized will now clea its internal data, prior to constructing the object that it contains.

-

Types

+

Types and objects

template class value_initialized<T>

@@ -312,19 +312,22 @@ the wrapped object is always performed with the get() idiom:

value_initialized<int> x ;
get(x) = 1 ; // OK

value_initialized<int const> cx ;
get(x) = 1 ; // ERROR: Cannot modify a const object

value_initialized<int> const x_c ;
get(x_c) = 1 ; // ERROR: Cannot modify a const object

value_initialized<int const> const cx_c ;
get(cx_c) = 1 ; // ERROR: Cannot modify a const object
-

class initialized_value

+

initialized_value

 namespace boost {
-class initialized_value
+class initialized_value_t
 {
   public :
     template <class T> operator T() const ;
 };
+
+initialized_value_t const initialized_value = {} ;
+
 } // namespace boost
 
-The class initialized_value provides a convenient way to get +initialized_value provides a convenient way to get an initialized value: its conversion operator provides an appropriate value-initialized object for any CopyConstructible type. @@ -343,7 +346,7 @@ is rather short now (T), but could of course be more like Namespace::Template<Arg>::Type. Instead, one could use initialized_value as follows:
-  T var = initialized_value();
+  T var = initialized_value ;
 

References

@@ -368,13 +371,15 @@ Special thanks to Björn Karlsson who carefully edited and completed this do

value_initialized was reimplemented by Fernando Cacciola and Niels Dekker for Boost release version 1.35 (2008), offering a workaround to various compiler issues.

+

initialized_value was written by Niels Dekker, and added to Boost release version 1.36 (2008). +

Developed by Fernando Cacciola, the latest version of this file can be found at www.boost.org.


-

Revised 16 January 2008

+

Revised 23 May 2008

© Copyright Fernando Cacciola, 2002, 2008.

diff --git a/value_init_test.cpp b/value_init_test.cpp index b7dd956..7b07b22 100644 --- a/value_init_test.cpp +++ b/value_init_test.cpp @@ -7,7 +7,8 @@ // Test program for "boost/utility/value_init.hpp" // // 21 Ago 2002 (Created) Fernando Cacciola -// 18 Feb 2008 (Added tests regarding compiler issues and initialized_value) Fernando Cacciola, Niels Dekker +// 15 Jan 2008 (Added tests regarding compiler issues) Fernando Cacciola, Niels Dekker +// 23 May 2008 (Added tests regarding initialized_value) Niels Dekker #include // For memcmp. #include @@ -183,7 +184,7 @@ struct CopyFunctionCallTester template void check_initialized_value ( T const& y ) { - T initializedValue = boost::initialized_value() ; + T initializedValue = boost::initialized_value ; BOOST_CHECK ( y == initializedValue ) ; } From 4a564744fe9dcbf87c85c60b89f372de63cc99f3 Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Wed, 25 Jun 2008 23:27:56 +0000 Subject: [PATCH 08/30] documentation update, added function exception::diagnostic_information, added std::exception to_string overload, removed tabs from source files [SVN r46697] --- include/boost/exception.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/boost/exception.hpp b/include/boost/exception.hpp index aca1409..d805002 100644 --- a/include/boost/exception.hpp +++ b/include/boost/exception.hpp @@ -6,6 +6,12 @@ #ifndef UUID_1D94A7C6054E11DB9804B622A1EF5492 #define UUID_1D94A7C6054E11DB9804B622A1EF5492 +#include +#include +#include +#include +#include +#include #include #include #include From f1ec0c4d04d593a58e95833c13a571e08da3bf5b Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 26 Jun 2008 19:20:56 +0000 Subject: [PATCH 09/30] Fix a character encoding error. [SVN r46740] --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 7605aef..ff22fb4 100644 --- a/index.html +++ b/index.html @@ -29,7 +29,7 @@ value_init


-

© Copyright Beman Dawes, 2001

+

© Copyright Beman Dawes, 2001

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at From 177ee78bbb5e1283f914e77c936ac586a15a5abc Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sat, 28 Jun 2008 13:45:21 +0000 Subject: [PATCH 10/30] =?UTF-8?q?With=20his=20kind=20permission,=20change?= =?UTF-8?q?=20Jaakko=20"J=C3=A4rvi"=20to=20"Jarvi"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [SVN r46808] --- enable_if/test/constructors.cpp | 2 +- enable_if/test/dummy_arg_disambiguation.cpp | 2 +- enable_if/test/lazy.cpp | 2 +- enable_if/test/lazy_test.cpp | 2 +- enable_if/test/member_templates.cpp | 2 +- enable_if/test/namespace_disambiguation.cpp | 2 +- enable_if/test/no_disambiguation.cpp | 2 +- enable_if/test/partial_specializations.cpp | 2 +- include/boost/ref.hpp | 2 +- include/boost/utility/enable_if.hpp | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/enable_if/test/constructors.cpp b/enable_if/test/constructors.cpp index 889133d..0d465de 100644 --- a/enable_if/test/constructors.cpp +++ b/enable_if/test/constructors.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/dummy_arg_disambiguation.cpp b/enable_if/test/dummy_arg_disambiguation.cpp index 90275e9..60dfdfd 100644 --- a/enable_if/test/dummy_arg_disambiguation.cpp +++ b/enable_if/test/dummy_arg_disambiguation.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/lazy.cpp b/enable_if/test/lazy.cpp index 117ec41..f04111e 100644 --- a/enable_if/test/lazy.cpp +++ b/enable_if/test/lazy.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/lazy_test.cpp b/enable_if/test/lazy_test.cpp index 10bb60c..9ec5324 100644 --- a/enable_if/test/lazy_test.cpp +++ b/enable_if/test/lazy_test.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/member_templates.cpp b/enable_if/test/member_templates.cpp index f7c00a0..55e2d80 100644 --- a/enable_if/test/member_templates.cpp +++ b/enable_if/test/member_templates.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/namespace_disambiguation.cpp b/enable_if/test/namespace_disambiguation.cpp index a53d3a7..45d4f0a 100644 --- a/enable_if/test/namespace_disambiguation.cpp +++ b/enable_if/test/namespace_disambiguation.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/no_disambiguation.cpp b/enable_if/test/no_disambiguation.cpp index 122d600..e2416ed 100644 --- a/enable_if/test/no_disambiguation.cpp +++ b/enable_if/test/no_disambiguation.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/partial_specializations.cpp b/enable_if/test/partial_specializations.cpp index 5c322ae..1d4db99 100644 --- a/enable_if/test/partial_specializations.cpp +++ b/enable_if/test/partial_specializations.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index ab09ae7..330ca65 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -15,7 +15,7 @@ // // ref.hpp - ref/cref, useful helper functions // -// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) // Copyright (C) 2001, 2002 Peter Dimov // Copyright (C) 2002 David Abrahams // diff --git a/include/boost/utility/enable_if.hpp b/include/boost/utility/enable_if.hpp index d77d108..d292c6a 100644 --- a/include/boost/utility/enable_if.hpp +++ b/include/boost/utility/enable_if.hpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) From 3c5c2bc107790c476e4523d3ab9e27173fc24327 Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Sat, 5 Jul 2008 11:16:38 +0000 Subject: [PATCH 11/30] Moved utility\swap to the trunk, as discussed in trac issue #2056. [SVN r47093] --- include/boost/swap.hpp | 12 ++ include/boost/utility/swap.hpp | 51 +++++++++ index.html | 1 + swap.html | 94 +++++++++++++++ swap/test/Jamfile.v2 | 53 +++++++++ swap/test/lib_header_1.cpp | 18 +++ swap/test/lib_header_2.cpp | 20 ++++ swap/test/mixed_headers_1.cpp | 20 ++++ swap/test/mixed_headers_2.cpp | 20 ++++ swap/test/primitive.cpp | 44 +++++++ swap/test/root_header_1.cpp | 18 +++ swap/test/root_header_2.cpp | 20 ++++ swap/test/specialized_in_boost.cpp | 72 ++++++++++++ swap/test/specialized_in_global.cpp | 60 ++++++++++ swap/test/specialized_in_other.cpp | 72 ++++++++++++ swap/test/specialized_in_std.cpp | 70 ++++++++++++ swap/test/swap_arrays.cpp | 78 +++++++++++++ swap/test/swap_test_class.hpp | 171 ++++++++++++++++++++++++++++ 18 files changed, 894 insertions(+) create mode 100644 include/boost/swap.hpp create mode 100644 include/boost/utility/swap.hpp create mode 100644 swap.html create mode 100644 swap/test/Jamfile.v2 create mode 100644 swap/test/lib_header_1.cpp create mode 100644 swap/test/lib_header_2.cpp create mode 100644 swap/test/mixed_headers_1.cpp create mode 100644 swap/test/mixed_headers_2.cpp create mode 100644 swap/test/primitive.cpp create mode 100644 swap/test/root_header_1.cpp create mode 100644 swap/test/root_header_2.cpp create mode 100644 swap/test/specialized_in_boost.cpp create mode 100644 swap/test/specialized_in_global.cpp create mode 100644 swap/test/specialized_in_other.cpp create mode 100644 swap/test/specialized_in_std.cpp create mode 100644 swap/test/swap_arrays.cpp create mode 100644 swap/test/swap_test_class.hpp diff --git a/include/boost/swap.hpp b/include/boost/swap.hpp new file mode 100644 index 0000000..2d8b44c --- /dev/null +++ b/include/boost/swap.hpp @@ -0,0 +1,12 @@ +// Copyright (C) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_SWAP_HPP +#define BOOST_SWAP_HPP + +#include "./utility/swap.hpp" + +#endif diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp new file mode 100644 index 0000000..952adf5 --- /dev/null +++ b/include/boost/utility/swap.hpp @@ -0,0 +1,51 @@ +// Copyright (C) 2007, 2008 Steven Watanabe, Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// For more information, see http://www.boost.org +// +// Update: +// 29 June 2008 (Added support for built-in arrays.) Niels Dekker + + +#ifndef BOOST_UTILITY_SWAP_HPP +#define BOOST_UTILITY_SWAP_HPP + +#include //for std::swap +#include //for std::size_t + +namespace boost_swap_impl +{ + template + void swap_impl(T& left, T& right) + { + using std::swap;//use std::swap if argument dependent lookup fails + swap(left,right); + } + + template + void swap_impl(T (& left)[N], T (& right)[N]) + { + for (std::size_t i = 0; i < N; ++i) + { + ::boost_swap_impl::swap_impl(left[i], right[i]); + } + } +} + +namespace boost +{ + namespace swap_adl_barrier + { + template + void swap(T& left, T& right) + { + ::boost_swap_impl::swap_impl(left, right); + } + } + + using swap_adl_barrier::swap; +} + +#endif diff --git a/index.html b/index.html index ff22fb4..5af6f75 100644 --- a/index.html +++ b/index.html @@ -24,6 +24,7 @@ iterator_adaptors
generator iterator adaptors
operators
+ swap
throw_exception
utility
value_init

diff --git a/swap.html b/swap.html new file mode 100644 index 0000000..e317b11 --- /dev/null +++ b/swap.html @@ -0,0 +1,94 @@ +? + + + + + Boost: Swap Documentation + + + + C++ Boost +

Swap

+ +

+ template<class T> void swap(T& left, T& right); +

+ + +

+ The template function boost::swap allows the values of two variables to be swapped, using argument dependent lookup to select a specialized swap function if available. If no specialized swap function is available, std::swap is used. +

+ + +

Rationale

+

+ The generic std::swap function requires that the elements to be swapped are assignable and copy constructible. It is usually implemented using one copy construction and two assignments - this is often both unnecessarily restrictive and unnecessarily slow. In addition, where the generic swap implementation provides only the basic guarantee, specialized swap functions are often able to provide the no-throw exception guarantee (and it is considered best practice to do so where possible1).

+

+ The alternative to using argument dependent lookup in this situation is to provide a template specialization of std::swap for every type that requires a specialized swap. Although this is legal C++, no Boost libraries use this method, whereas many Boost libraries provide specialized swap functions in their own namespaces. +

+

+ boost::swap also supports swapping built-in arrays. Note that std::swap doesn't yet do so, but a request to add an overload of std::swap for built-in arrays has been well-received by the Library Working Group of the C++ Standards Committee2. +

+ + +

Exception Safety

+

+ boost::swap provides the same exception guarantee as the underlying swap function used, with one exception; for an array of type T[n], where n > 1 and the underlying swap function for T provides the strong exception guarantee, boost::swap provides only the basic exception guarantee. +

+ + +

Requirements

+

Either:

+
    +
  • T must be assignable
  • +
  • T must be copy constructible
  • +
+

Or:

+
    +
  • A function with the signature swap(T&,T&) is available via argument dependent lookup
  • +
+

Or:

+
    +
  • A template specialization of std::swap exists for T
  • +
+

Or:

+
    +
  • T is a built-in array of swappable elements
  • +
+ + + +

Portability

+

+ Several older compilers do not support argument dependent lookup – on these compilers boost::swap will call std::swap, ignoring any specialized swap functions that could be found as a result of argument dependent lookup. +

+ + +

Credits

+
    +
  • + Niels Dekker - for implementing and documenting support for built-in arrays +
  • +
  • + Joseph Gauterin - for the initial idea, implementation, tests, and documentation +
  • +
  • + Steven Wanatabe - for the idea to use a barrier namespace, enabling the function to have the name 'swap' without introducing ambiguity or infinite recursion +
  • +
+ + +
+

[1]Scott Meyers, Effective C++ Third Edition, Item 25: "Consider support for a non-throwing swap"

+

[2]LWG issue 809 (std::swap should be overloaded for array types)

+ + +
+

Revised: 3 July 2008

+

+ Copyright 2007, 2008 Joseph Gauterin. Use, modification, and distribution are subject to the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.) +

+ + + diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 new file mode 100644 index 0000000..758bdaa --- /dev/null +++ b/swap/test/Jamfile.v2 @@ -0,0 +1,53 @@ +# Copyright (c) 2007, 2008 Joseph Gauterin +# +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# bring in rules for testing +import testing ; + +test-suite utility/swap + : + [ compile root_header_1.cpp ] + [ compile root_header_2.cpp ] + [ compile lib_header_1.cpp ] + [ compile lib_header_2.cpp ] + [ compile mixed_headers_1.cpp ] + [ compile mixed_headers_2.cpp ] + [ run primitive.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + ; + + +# Copyright (c) 2007, 2008 Joseph Gauterin +# +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# bring in rules for testing +import testing ; + +test-suite utility/swap + : + [ compile root_header_1.cpp ] + [ compile root_header_2.cpp ] + [ compile lib_header_1.cpp ] + [ compile lib_header_2.cpp ] + [ compile mixed_headers_1.cpp ] + [ compile mixed_headers_2.cpp ] + [ run primitive.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + ; + + + diff --git a/swap/test/lib_header_1.cpp b/swap/test/lib_header_1.cpp new file mode 100644 index 0000000..ea7c99a --- /dev/null +++ b/swap/test/lib_header_1.cpp @@ -0,0 +1,18 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap header compiles as a standalone translation unit + +#include +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap header compiles as a standalone translation unit + +#include diff --git a/swap/test/lib_header_2.cpp b/swap/test/lib_header_2.cpp new file mode 100644 index 0000000..0c9e409 --- /dev/null +++ b/swap/test/lib_header_2.cpp @@ -0,0 +1,20 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap header include guards work correctly + +#include +#include +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap header include guards work correctly + +#include +#include diff --git a/swap/test/mixed_headers_1.cpp b/swap/test/mixed_headers_1.cpp new file mode 100644 index 0000000..0c7571e --- /dev/null +++ b/swap/test/mixed_headers_1.cpp @@ -0,0 +1,20 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap headers work when both are included + +#include +#include +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap headers work when both are included + +#include +#include diff --git a/swap/test/mixed_headers_2.cpp b/swap/test/mixed_headers_2.cpp new file mode 100644 index 0000000..217873a --- /dev/null +++ b/swap/test/mixed_headers_2.cpp @@ -0,0 +1,20 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap headers work when both are included + +#include +#include +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap headers work when both are included + +#include +#include diff --git a/swap/test/primitive.cpp b/swap/test/primitive.cpp new file mode 100644 index 0000000..76cd7b0 --- /dev/null +++ b/swap/test/primitive.cpp @@ -0,0 +1,44 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +int test_main(int, char*[]) +{ + int object1 = 1; + int object2 = 2; + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1,2); + BOOST_CHECK_EQUAL(object2,1); + + return 0; +} +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +int test_main(int, char*[]) +{ + int object1 = 1; + int object2 = 2; + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1,2); + BOOST_CHECK_EQUAL(object2,1); + + return 0; +} diff --git a/swap/test/root_header_1.cpp b/swap/test/root_header_1.cpp new file mode 100644 index 0000000..efa0028 --- /dev/null +++ b/swap/test/root_header_1.cpp @@ -0,0 +1,18 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap header compiles as a standalone translation unit + +#include +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap header compiles as a standalone translation unit + +#include diff --git a/swap/test/root_header_2.cpp b/swap/test/root_header_2.cpp new file mode 100644 index 0000000..d7e00f3 --- /dev/null +++ b/swap/test/root_header_2.cpp @@ -0,0 +1,20 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap header include guards work correctly + +#include +#include +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap header include guards work correctly + +#include +#include diff --git a/swap/test/specialized_in_boost.cpp b/swap/test/specialized_in_boost.cpp new file mode 100644 index 0000000..bc3840f --- /dev/null +++ b/swap/test/specialized_in_boost.cpp @@ -0,0 +1,72 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in namespace boost +namespace boost +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace boost +namespace boost +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int test_main(int, char*[]) +{ + boost::swap_test_class object1; + boost::swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0); + + return 0; +} +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in namespace boost +namespace boost +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace boost +namespace boost +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int test_main(int, char*[]) +{ + boost::swap_test_class object1; + boost::swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0); + + return 0; +} diff --git a/swap/test/specialized_in_global.cpp b/swap/test/specialized_in_global.cpp new file mode 100644 index 0000000..7f46187 --- /dev/null +++ b/swap/test/specialized_in_global.cpp @@ -0,0 +1,60 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + +//Provide swap function in gloabl namespace +void swap(swap_test_class& left, swap_test_class& right) +{ + left.swap(right); +} + +int test_main(int, char*[]) +{ + swap_test_class object1; + swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); + + return 0; +} +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + +//Provide swap function in gloabl namespace +void swap(swap_test_class& left, swap_test_class& right) +{ + left.swap(right); +} + +int test_main(int, char*[]) +{ + swap_test_class object1; + swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); + + return 0; +} diff --git a/swap/test/specialized_in_other.cpp b/swap/test/specialized_in_other.cpp new file mode 100644 index 0000000..7dccab4 --- /dev/null +++ b/swap/test/specialized_in_other.cpp @@ -0,0 +1,72 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in namespace other +namespace other +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace other +namespace other +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int test_main(int, char*[]) +{ + other::swap_test_class object1; + other::swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0); + + return 0; +} +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in namespace other +namespace other +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace other +namespace other +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int test_main(int, char*[]) +{ + other::swap_test_class object1; + other::swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0); + + return 0; +} diff --git a/swap/test/specialized_in_std.cpp b/swap/test/specialized_in_std.cpp new file mode 100644 index 0000000..c6effb0 --- /dev/null +++ b/swap/test/specialized_in_std.cpp @@ -0,0 +1,70 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + + +//Provide swap function in namespace std +namespace std +{ + template <> + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int test_main(int, char*[]) +{ + swap_test_class object1; + swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); + + return 0; +} +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + + +//Provide swap function in namespace std +namespace std +{ + template <> + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int test_main(int, char*[]) +{ + swap_test_class object1; + swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); + + return 0; +} diff --git a/swap/test/swap_arrays.cpp b/swap/test/swap_arrays.cpp new file mode 100644 index 0000000..f032f5b --- /dev/null +++ b/swap/test/swap_arrays.cpp @@ -0,0 +1,78 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + + +int test_main(int, char*[]) +{ + const std::size_t dimension = 7; + + swap_test_class array1[dimension]; + swap_test_class array2[dimension]; + boost::swap(array1, array2); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + swap_test_class::reset(); + + const std::size_t firstDimension = 3; + const std::size_t secondDimension = 4; + + swap_test_class two_d_array1[firstDimension][secondDimension]; + swap_test_class two_d_array2[firstDimension][secondDimension]; + boost::swap(two_d_array1, two_d_array1); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + return 0; +} +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + + +int test_main(int, char*[]) +{ + const std::size_t dimension = 7; + + swap_test_class array1[dimension]; + swap_test_class array2[dimension]; + boost::swap(array1, array2); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + swap_test_class::reset(); + + const std::size_t firstDimension = 3; + const std::size_t secondDimension = 4; + + swap_test_class two_d_array1[firstDimension][secondDimension]; + swap_test_class two_d_array2[firstDimension][secondDimension]; + boost::swap(two_d_array1, two_d_array1); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + return 0; +} diff --git a/swap/test/swap_test_class.hpp b/swap/test/swap_test_class.hpp new file mode 100644 index 0000000..2b23f20 --- /dev/null +++ b/swap/test/swap_test_class.hpp @@ -0,0 +1,171 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap header compiles as a standalone translation unit + +#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP +#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP + + +class swap_test_class +{ +public: + swap_test_class() + { + ++constructCount(); + } + + ~swap_test_class() + { + ++destructCount(); + } + + swap_test_class(const swap_test_class&) + { + ++copyCount(); + ++destructCount(); + } + + swap_test_class& operator=(const swap_test_class&) + { + ++copyCount(); + return *this; + } + + void swap(swap_test_class& other) + { + ++swapCount(); + } + + + static unsigned int swap_count(){ return swapCount(); } + static unsigned int copy_count(){ return copyCount(); } + static unsigned int construct_count(){ return constructCount(); } + static unsigned int destruct_count(){ return destructCount(); } + + static void reset() + { + swapCount() = 0; + copyCount() = 0; + constructCount() = 0; + destructCount() = 0; + } + +private: + static unsigned int& swapCount() + { + static unsigned int value = 0; + return value; + } + + static unsigned int& copyCount() + { + static unsigned int value = 0; + return value; + } + + static unsigned int& constructCount() + { + static unsigned int value = 0; + return value; + } + + static unsigned int& destructCount() + { + static unsigned int value = 0; + return value; + } + +}; + +#endif + +// Copyright (c) 2007 Joseph Gauterin +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests that the swap header compiles as a standalone translation unit + +#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP +#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP + + +class swap_test_class +{ +public: + swap_test_class() + { + ++constructCount(); + } + + ~swap_test_class() + { + ++destructCount(); + } + + swap_test_class(const swap_test_class&) + { + ++copyCount(); + ++destructCount(); + } + + swap_test_class& operator=(const swap_test_class&) + { + ++copyCount(); + return *this; + } + + void swap(swap_test_class& other) + { + ++swapCount(); + } + + + static unsigned int swap_count(){ return swapCount(); } + static unsigned int copy_count(){ return copyCount(); } + static unsigned int construct_count(){ return constructCount(); } + static unsigned int destruct_count(){ return destructCount(); } + + static void reset() + { + swapCount() = 0; + copyCount() = 0; + constructCount() = 0; + destructCount() = 0; + } + +private: + static unsigned int& swapCount() + { + static unsigned int value = 0; + return value; + } + + static unsigned int& copyCount() + { + static unsigned int value = 0; + return value; + } + + static unsigned int& constructCount() + { + static unsigned int value = 0; + return value; + } + + static unsigned int& destructCount() + { + static unsigned int value = 0; + return value; + } + +}; + +#endif + + From cce5d77d2bf28740f56c15b2cc5d7d43e72145d8 Mon Sep 17 00:00:00 2001 From: Ronald Garcia Date: Thu, 10 Jul 2008 19:28:49 +0000 Subject: [PATCH 12/30] Added unwrap_ref. [SVN r47295] --- include/boost/ref.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 330ca65..9c996ab 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -173,6 +173,12 @@ class unwrap_reference # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +template inline typename unwrap_reference::type& +unwrap_ref(T& t) +{ + return t; +} + } // namespace boost #endif // #ifndef BOOST_REF_HPP_INCLUDED From 1823481d9610a5922998f2c1abe0823239353f4e Mon Sep 17 00:00:00 2001 From: Ronald Garcia Date: Thu, 10 Jul 2008 19:29:02 +0000 Subject: [PATCH 13/30] Added tests for unwrap_ref. [SVN r47296] --- ref_test.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/ref_test.cpp b/ref_test.cpp index 63fc9e5..93468ee 100644 --- a/ref_test.cpp +++ b/ref_test.cpp @@ -68,11 +68,53 @@ struct ref_wrapper } }; +struct copy_counter { + static int count_; + copy_counter(copy_counter const& other) { + ++count_; + } + copy_counter() {} + static void reset() { count_ = 0; } + static int count() { return copy_counter::count_; } +}; + +int copy_counter::count_ = 0; + } // namespace unnamed +template +void do_unwrap(T t) { + + /* typename unwrap_reference::type& lt = */ + unwrap_ref(t); + +} + +void unwrap_test() { + + int i = 3; + const int ci = 2; + + do_unwrap(i); + do_unwrap(ci); + do_unwrap(ref(i)); + do_unwrap(cref(ci)); + do_unwrap(ref(ci)); + + copy_counter cc; + BOOST_CHECK(cc.count() == 0); + + do_unwrap(cc); + do_unwrap(ref(cc)); + do_unwrap(cref(cc)); + + BOOST_CHECK(cc.count() == 1); +} + int test_main(int, char * []) { ref_wrapper::test(1); ref_wrapper::test(1); + unwrap_test(); return 0; } From 0ce3885d59c7ffd129ae36331883f02d9c280068 Mon Sep 17 00:00:00 2001 From: Ronald Garcia Date: Thu, 10 Jul 2008 23:01:26 +0000 Subject: [PATCH 14/30] Added an anonymous unwrapping test. [SVN r47297] --- ref_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ref_test.cpp b/ref_test.cpp index 93468ee..d4237b4 100644 --- a/ref_test.cpp +++ b/ref_test.cpp @@ -109,6 +109,7 @@ void unwrap_test() { do_unwrap(cref(cc)); BOOST_CHECK(cc.count() == 1); + BOOST_CHECK(unwrap_ref(ref(cc)).count() == 1); } int test_main(int, char * []) From 28fff2d8210e3967984511fcfb7f811915e4c907 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Sat, 12 Jul 2008 17:56:01 +0000 Subject: [PATCH 15/30] Remove duplicate content. [SVN r47360] --- swap/test/Jamfile.v2 | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index 758bdaa..a13cbd0 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -22,32 +22,5 @@ test-suite utility/swap [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; - - -# Copyright (c) 2007, 2008 Joseph Gauterin -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -# bring in rules for testing -import testing ; - -test-suite utility/swap - : - [ compile root_header_1.cpp ] - [ compile root_header_2.cpp ] - [ compile lib_header_1.cpp ] - [ compile lib_header_2.cpp ] - [ compile mixed_headers_1.cpp ] - [ compile mixed_headers_2.cpp ] - [ run primitive.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] - ; - From 6098304ea806deb6d8b5fec14c268050829ffa67 Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Sat, 19 Jul 2008 19:40:12 +0000 Subject: [PATCH 16/30] Corrected duplicated file contents [SVN r47607] --- swap/test/lib_header_1.cpp | 11 +--- swap/test/lib_header_2.cpp | 9 --- swap/test/mixed_headers_1.cpp | 9 --- swap/test/mixed_headers_2.cpp | 8 --- swap/test/primitive.cpp | 21 ------- swap/test/root_header_1.cpp | 8 --- swap/test/root_header_2.cpp | 9 --- swap/test/specialized_in_boost.cpp | 35 ----------- swap/test/specialized_in_global.cpp | 29 --------- swap/test/specialized_in_other.cpp | 35 ----------- swap/test/specialized_in_std.cpp | 34 ----------- swap/test/swap_arrays.cpp | 38 ------------ swap/test/swap_test_class.hpp | 91 +---------------------------- 13 files changed, 3 insertions(+), 334 deletions(-) diff --git a/swap/test/lib_header_1.cpp b/swap/test/lib_header_1.cpp index ea7c99a..d3efc63 100644 --- a/swap/test/lib_header_1.cpp +++ b/swap/test/lib_header_1.cpp @@ -6,13 +6,4 @@ // Tests that the swap header compiles as a standalone translation unit -#include -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Tests that the swap header compiles as a standalone translation unit - -#include +#include \ No newline at end of file diff --git a/swap/test/lib_header_2.cpp b/swap/test/lib_header_2.cpp index 0c9e409..e88909d 100644 --- a/swap/test/lib_header_2.cpp +++ b/swap/test/lib_header_2.cpp @@ -8,13 +8,4 @@ #include #include -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// Tests that the swap header include guards work correctly - -#include -#include diff --git a/swap/test/mixed_headers_1.cpp b/swap/test/mixed_headers_1.cpp index 0c7571e..cdb9fe5 100644 --- a/swap/test/mixed_headers_1.cpp +++ b/swap/test/mixed_headers_1.cpp @@ -8,13 +8,4 @@ #include #include -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// Tests that the swap headers work when both are included - -#include -#include diff --git a/swap/test/mixed_headers_2.cpp b/swap/test/mixed_headers_2.cpp index 217873a..94e9d87 100644 --- a/swap/test/mixed_headers_2.cpp +++ b/swap/test/mixed_headers_2.cpp @@ -8,13 +8,5 @@ #include #include -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// Tests that the swap headers work when both are included -#include -#include diff --git a/swap/test/primitive.cpp b/swap/test/primitive.cpp index 76cd7b0..380edb3 100644 --- a/swap/test/primitive.cpp +++ b/swap/test/primitive.cpp @@ -20,25 +20,4 @@ int test_main(int, char*[]) return 0; } -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -#include -#define BOOST_INCLUDE_MAIN -#include - -int test_main(int, char*[]) -{ - int object1 = 1; - int object2 = 2; - - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(object1,2); - BOOST_CHECK_EQUAL(object2,1); - - return 0; -} diff --git a/swap/test/root_header_1.cpp b/swap/test/root_header_1.cpp index efa0028..575d2cb 100644 --- a/swap/test/root_header_1.cpp +++ b/swap/test/root_header_1.cpp @@ -7,12 +7,4 @@ // Tests that the swap header compiles as a standalone translation unit #include -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// Tests that the swap header compiles as a standalone translation unit - -#include diff --git a/swap/test/root_header_2.cpp b/swap/test/root_header_2.cpp index d7e00f3..d26b3a6 100644 --- a/swap/test/root_header_2.cpp +++ b/swap/test/root_header_2.cpp @@ -8,13 +8,4 @@ #include #include -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// Tests that the swap header include guards work correctly - -#include -#include diff --git a/swap/test/specialized_in_boost.cpp b/swap/test/specialized_in_boost.cpp index bc3840f..55ac390 100644 --- a/swap/test/specialized_in_boost.cpp +++ b/swap/test/specialized_in_boost.cpp @@ -34,39 +34,4 @@ int test_main(int, char*[]) return 0; } -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -#include -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in namespace boost -namespace boost -{ - #include "./swap_test_class.hpp" -} - -//Provide swap function in namespace boost -namespace boost -{ - void swap(swap_test_class& left, swap_test_class& right) - { - left.swap(right); - } -} - -int test_main(int, char*[]) -{ - boost::swap_test_class object1; - boost::swap_test_class object2; - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1); - BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0); - - return 0; -} diff --git a/swap/test/specialized_in_global.cpp b/swap/test/specialized_in_global.cpp index 7f46187..f76754f 100644 --- a/swap/test/specialized_in_global.cpp +++ b/swap/test/specialized_in_global.cpp @@ -28,33 +28,4 @@ int test_main(int, char*[]) return 0; } -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -#include -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in the global namespace -#include "./swap_test_class.hpp" - -//Provide swap function in gloabl namespace -void swap(swap_test_class& left, swap_test_class& right) -{ - left.swap(right); -} - -int test_main(int, char*[]) -{ - swap_test_class object1; - swap_test_class object2; - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); - - return 0; -} diff --git a/swap/test/specialized_in_other.cpp b/swap/test/specialized_in_other.cpp index 7dccab4..c3071f5 100644 --- a/swap/test/specialized_in_other.cpp +++ b/swap/test/specialized_in_other.cpp @@ -34,39 +34,4 @@ int test_main(int, char*[]) return 0; } -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -#include -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in namespace other -namespace other -{ - #include "./swap_test_class.hpp" -} - -//Provide swap function in namespace other -namespace other -{ - void swap(swap_test_class& left, swap_test_class& right) - { - left.swap(right); - } -} - -int test_main(int, char*[]) -{ - other::swap_test_class object1; - other::swap_test_class object2; - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1); - BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0); - - return 0; -} diff --git a/swap/test/specialized_in_std.cpp b/swap/test/specialized_in_std.cpp index c6effb0..641aa82 100644 --- a/swap/test/specialized_in_std.cpp +++ b/swap/test/specialized_in_std.cpp @@ -33,38 +33,4 @@ int test_main(int, char*[]) return 0; } -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -#include -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in the global namespace -#include "./swap_test_class.hpp" - - -//Provide swap function in namespace std -namespace std -{ - template <> - void swap(swap_test_class& left, swap_test_class& right) - { - left.swap(right); - } -} - -int test_main(int, char*[]) -{ - swap_test_class object1; - swap_test_class object2; - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); - - return 0; -} diff --git a/swap/test/swap_arrays.cpp b/swap/test/swap_arrays.cpp index f032f5b..96b7939 100644 --- a/swap/test/swap_arrays.cpp +++ b/swap/test/swap_arrays.cpp @@ -37,42 +37,4 @@ int test_main(int, char*[]) return 0; } -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -#include -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in the global namespace -#include "./swap_test_class.hpp" - - -int test_main(int, char*[]) -{ - const std::size_t dimension = 7; - - swap_test_class array1[dimension]; - swap_test_class array2[dimension]; - boost::swap(array1, array2); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); - - swap_test_class::reset(); - - const std::size_t firstDimension = 3; - const std::size_t secondDimension = 4; - - swap_test_class two_d_array1[firstDimension][secondDimension]; - swap_test_class two_d_array2[firstDimension][secondDimension]; - boost::swap(two_d_array1, two_d_array1); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); - - return 0; -} diff --git a/swap/test/swap_test_class.hpp b/swap/test/swap_test_class.hpp index 2b23f20..aa68444 100644 --- a/swap/test/swap_test_class.hpp +++ b/swap/test/swap_test_class.hpp @@ -1,10 +1,10 @@ -// Copyright (c) 2007 Joseph Gauterin +// Copyright (c) 2007-2008 Joseph Gauterin // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Tests that the swap header compiles as a standalone translation unit +// Tests class used by the Boost.Swap tests #ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP #define BOOST_UTILITY_SWAP_TEST_CLASS_HPP @@ -82,90 +82,3 @@ private: }; #endif - -// Copyright (c) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Tests that the swap header compiles as a standalone translation unit - -#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP -#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP - - -class swap_test_class -{ -public: - swap_test_class() - { - ++constructCount(); - } - - ~swap_test_class() - { - ++destructCount(); - } - - swap_test_class(const swap_test_class&) - { - ++copyCount(); - ++destructCount(); - } - - swap_test_class& operator=(const swap_test_class&) - { - ++copyCount(); - return *this; - } - - void swap(swap_test_class& other) - { - ++swapCount(); - } - - - static unsigned int swap_count(){ return swapCount(); } - static unsigned int copy_count(){ return copyCount(); } - static unsigned int construct_count(){ return constructCount(); } - static unsigned int destruct_count(){ return destructCount(); } - - static void reset() - { - swapCount() = 0; - copyCount() = 0; - constructCount() = 0; - destructCount() = 0; - } - -private: - static unsigned int& swapCount() - { - static unsigned int value = 0; - return value; - } - - static unsigned int& copyCount() - { - static unsigned int value = 0; - return value; - } - - static unsigned int& constructCount() - { - static unsigned int value = 0; - return value; - } - - static unsigned int& destructCount() - { - static unsigned int value = 0; - return value; - } - -}; - -#endif - - From ece69925403cc9a6e0a29faf2df2518da47d91f7 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 20 Jul 2008 11:05:49 +0000 Subject: [PATCH 17/30] Fixed silly little bug of mine in swap/test/swap_arrays.cpp [SVN r47626] --- swap/test/swap_arrays.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swap/test/swap_arrays.cpp b/swap/test/swap_arrays.cpp index 96b7939..6689db7 100644 --- a/swap/test/swap_arrays.cpp +++ b/swap/test/swap_arrays.cpp @@ -30,7 +30,7 @@ int test_main(int, char*[]) swap_test_class two_d_array1[firstDimension][secondDimension]; swap_test_class two_d_array2[firstDimension][secondDimension]; - boost::swap(two_d_array1, two_d_array1); + boost::swap(two_d_array1, two_d_array2); BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension); BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); From 64a0e0cb205cb12abb3f608f31c548706790511a Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 20 Jul 2008 12:13:33 +0000 Subject: [PATCH 18/30] Added swap_test_class swap functions to test/swap_arrays.cpp. My fault, they should have been there already! [SVN r47628] --- swap/test/swap_arrays.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/swap/test/swap_arrays.cpp b/swap/test/swap_arrays.cpp index 6689db7..154ae30 100644 --- a/swap/test/swap_arrays.cpp +++ b/swap/test/swap_arrays.cpp @@ -11,6 +11,25 @@ //Put test class in the global namespace #include "./swap_test_class.hpp" +//Provide swap function in both the namespace of swap_test_class +//(which is the global namespace), and the std namespace. +//It's common to provide a swap function for a class in both +//namespaces. Scott Meyers recommends doing so: Effectice C++, +//Third Edition, item 25, "Consider support for a non-throwing swap". +void swap(swap_test_class& left, swap_test_class& right) +{ + left.swap(right); +} + +namespace std +{ + template <> + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + int test_main(int, char*[]) { From 899c92420c526c7ed85bcd8587a0948c955111eb Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 20 Jul 2008 12:18:25 +0000 Subject: [PATCH 19/30] Fixed silly little typo of mine, in test/swap_arrays.cpp [SVN r47629] --- swap/test/swap_arrays.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swap/test/swap_arrays.cpp b/swap/test/swap_arrays.cpp index 154ae30..79c6d68 100644 --- a/swap/test/swap_arrays.cpp +++ b/swap/test/swap_arrays.cpp @@ -14,7 +14,7 @@ //Provide swap function in both the namespace of swap_test_class //(which is the global namespace), and the std namespace. //It's common to provide a swap function for a class in both -//namespaces. Scott Meyers recommends doing so: Effectice C++, +//namespaces. Scott Meyers recommends doing so: Effective C++, //Third Edition, item 25, "Consider support for a non-throwing swap". void swap(swap_test_class& left, swap_test_class& right) { From b311fcefb2478bbe3aea776f9686c188bd053fa9 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 25 Jul 2008 18:48:09 +0000 Subject: [PATCH 20/30] Added test_adl_barrier to swap/test, as discussed with Joseph Gauterin. [SVN r47808] --- swap/test/Jamfile.v2 | 5 ++--- swap/test/test_adl_barrier.cpp | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 swap/test/test_adl_barrier.cpp diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index a13cbd0..d648de2 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -20,7 +20,6 @@ test-suite utility/swap [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; - - diff --git a/swap/test/test_adl_barrier.cpp b/swap/test/test_adl_barrier.cpp new file mode 100644 index 0000000..e30a1b6 --- /dev/null +++ b/swap/test/test_adl_barrier.cpp @@ -0,0 +1,36 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// boost::swap internally does an unqualified function call to swap. +// This could have led to ambiguity or infinite recursion, when the +// objects to be swapped would themselves be from the boost namespace. +// If so, boost::swap itself might be found by argument dependent lookup +// (ADL). The implementation of boost::swap resolves this issue by +// using a barrier namespace. The following test checks this "ADL barrier". + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in namespace boost +namespace boost +{ + #include "./swap_test_class.hpp" +} + + +int test_main(int, char*[]) +{ + boost::swap_test_class object1; + boost::swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),0); + BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),3); + + return 0; +} + From b050431638e51abdcca52f0309cfde1f8c7e96f5 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sat, 26 Jul 2008 17:47:59 +0000 Subject: [PATCH 21/30] Added a newline to swap/test/lib_header_1.cpp, hoping to fix Sun 5.x compile issue, "Error: There is extra text on this line" [SVN r47829] --- swap/test/lib_header_1.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swap/test/lib_header_1.cpp b/swap/test/lib_header_1.cpp index d3efc63..923dea6 100644 --- a/swap/test/lib_header_1.cpp +++ b/swap/test/lib_header_1.cpp @@ -6,4 +6,5 @@ // Tests that the swap header compiles as a standalone translation unit -#include \ No newline at end of file +#include + From 3fd0ea6e7527118e0ea948b56f54140ed85422ba Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 27 Jul 2008 11:35:33 +0000 Subject: [PATCH 22/30] Added specialized_in_boost_and_other to swap/test, as discussed at "[boost] [swap] End-user allowed to add overloads to boost namespace?", http://lists.boost.org/Archives/boost/2008/07/140327.php [SVN r47839] --- swap/test/Jamfile.v2 | 15 +++--- swap/test/specialized_in_boost_and_other.cpp | 56 ++++++++++++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 swap/test/specialized_in_boost_and_other.cpp diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index d648de2..abce519 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -15,11 +15,12 @@ test-suite utility/swap [ compile lib_header_2.cpp ] [ compile mixed_headers_1.cpp ] [ compile mixed_headers_2.cpp ] - [ run primitive.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run primitive.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_boost_and_other.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; diff --git a/swap/test/specialized_in_boost_and_other.cpp b/swap/test/specialized_in_boost_and_other.cpp new file mode 100644 index 0000000..fc76251 --- /dev/null +++ b/swap/test/specialized_in_boost_and_other.cpp @@ -0,0 +1,56 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests whether two object in a namespace other than boost are properly +// swapped, when both boost and the other namespace have a custom swap function +// for their class. Note that it shouldn't be necessary for a class in an other +// namespace to have a custom swap function in boost, because the boost::swap +// utility should find the swap function in the other namespace, by argument +// dependent lookup (ADL). Unfortunately ADL isn't fully implemented by some +// specific compilers, including Intel C++ 8.1, MSVC 7.1, and Borland 5.9.3. +// Users of those compilers might consider adding a swap overload to the boost +// namespace. + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in namespace other +namespace other +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace boost +namespace boost +{ + void swap(::other::swap_test_class& left, ::other::swap_test_class& right) + { + left.swap(right); + } +} + +//Provide swap function in namespace other +namespace other +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int test_main(int, char*[]) +{ + other::swap_test_class object1; + other::swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0); + + return 0; +} + From c286d6222302d99cabfe9cabd87df8ab11e1c124 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 27 Jul 2008 12:46:45 +0000 Subject: [PATCH 23/30] Fixed comment in swap/test/specialized_in_boost_and_other.cpp [SVN r47840] --- swap/test/specialized_in_boost_and_other.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/swap/test/specialized_in_boost_and_other.cpp b/swap/test/specialized_in_boost_and_other.cpp index fc76251..9adc5c0 100644 --- a/swap/test/specialized_in_boost_and_other.cpp +++ b/swap/test/specialized_in_boost_and_other.cpp @@ -4,15 +4,15 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Tests whether two object in a namespace other than boost are properly -// swapped, when both boost and the other namespace have a custom swap function -// for their class. Note that it shouldn't be necessary for a class in an other -// namespace to have a custom swap function in boost, because the boost::swap -// utility should find the swap function in the other namespace, by argument -// dependent lookup (ADL). Unfortunately ADL isn't fully implemented by some -// specific compilers, including Intel C++ 8.1, MSVC 7.1, and Borland 5.9.3. -// Users of those compilers might consider adding a swap overload to the boost -// namespace. +// Tests whether instances of a class from a namespace other than boost are +// properly swapped, when both boost and the other namespace have a custom +// swap function for that class. Note that it shouldn't be necessary for a class +// in an other namespace to have a custom swap function in boost, because the +// boost::swap utility should find the swap function in the other namespace, by +// argument dependent lookup (ADL). Unfortunately ADL isn't fully implemented +// by some specific compiler versions, including Intel C++ 8.1, MSVC 7.1, and +// Borland 5.9.3. Users of those compilers might consider adding a swap overload +// to the boost namespace. #include #define BOOST_INCLUDE_MAIN From d215f2176c21b5e126f1fbeca988ba3de8a2bcfe Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Wed, 30 Jul 2008 08:04:34 +0000 Subject: [PATCH 24/30] Applied "swap.hpp.patch" by Steven Watanabe, "Re: [boost] [swap] How to fix ADL barrier for XL, Intel, GCC, Sun and Como?", http://lists.boost.org/Archives/boost/2008/07/140482.php [SVN r47877] --- include/boost/utility/swap.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp index 952adf5..16750c8 100644 --- a/include/boost/utility/swap.hpp +++ b/include/boost/utility/swap.hpp @@ -38,8 +38,8 @@ namespace boost { namespace swap_adl_barrier { - template - void swap(T& left, T& right) + template + void swap(T1& left, T2& right) { ::boost_swap_impl::swap_impl(left, right); } From 2aa48414c9c9151fdc627b23d14b062d3eade753 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 31 Jul 2008 20:18:04 +0000 Subject: [PATCH 25/30] Removed swap_adl_barrier namespace, as discussed at "Re: [boost] [swap] How to fix ADL barrier for XL, Intel, GCC, Sun and Como?", http://lists.boost.org/Archives/boost/2008/07/140511.php [SVN r47920] --- include/boost/utility/swap.hpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp index 16750c8..da293ee 100644 --- a/include/boost/utility/swap.hpp +++ b/include/boost/utility/swap.hpp @@ -36,16 +36,11 @@ namespace boost_swap_impl namespace boost { - namespace swap_adl_barrier + template + void swap(T1& left, T2& right) { - template - void swap(T1& left, T2& right) - { - ::boost_swap_impl::swap_impl(left, right); - } + ::boost_swap_impl::swap_impl(left, right); } - - using swap_adl_barrier::swap; } #endif From 1ecf3ceb74980b9a4975edc67fecb1563ac8271c Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sat, 2 Aug 2008 11:41:47 +0000 Subject: [PATCH 26/30] Added swap tests for std types, as discussed at "Re: [boost] [swap] Workaround for ADL failures of MSVC 7.1 and Borland okay?", http://lists.boost.org/Archives/boost/2008/08/140589.php [SVN r47943] --- swap/test/Jamfile.v2 | 7 ++++ swap/test/std_bitset.cpp | 33 ++++++++++++++++++ swap/test/std_dateorder.cpp | 32 ++++++++++++++++++ swap/test/std_string.cpp | 31 +++++++++++++++++ swap/test/std_typeinfo_ptr.cpp | 32 ++++++++++++++++++ swap/test/std_vector_of_boost.cpp | 54 ++++++++++++++++++++++++++++++ swap/test/std_vector_of_global.cpp | 47 ++++++++++++++++++++++++++ swap/test/std_vector_of_other.cpp | 54 ++++++++++++++++++++++++++++++ 8 files changed, 290 insertions(+) create mode 100644 swap/test/std_bitset.cpp create mode 100644 swap/test/std_dateorder.cpp create mode 100644 swap/test/std_string.cpp create mode 100644 swap/test/std_typeinfo_ptr.cpp create mode 100644 swap/test/std_vector_of_boost.cpp create mode 100644 swap/test/std_vector_of_global.cpp create mode 100644 swap/test/std_vector_of_other.cpp diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index abce519..d08a47a 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -21,6 +21,13 @@ test-suite utility/swap [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run specialized_in_boost_and_other.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run std_bitset.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run std_dateorder.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run std_string.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run std_typeinfo_ptr.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run std_vector_of_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run std_vector_of_global.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run std_vector_of_other.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; diff --git a/swap/test/std_bitset.cpp b/swap/test/std_bitset.cpp new file mode 100644 index 0000000..4b9fbae --- /dev/null +++ b/swap/test/std_bitset.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests swapping std::bitset objects by means of boost::swap. +// Unlike most other Standard C++ Library template classes, +// std::bitset does not have its own std::swap overload. + +#include +#define BOOST_INCLUDE_MAIN +#include + +#include + +int test_main(int, char*[]) +{ + typedef std::bitset<8> bitset_type; + const bitset_type initial_value1 = 1ul; + const bitset_type initial_value2 = 2ul; + + bitset_type object1 = initial_value1; + bitset_type object2 = initial_value2; + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1,initial_value2); + BOOST_CHECK_EQUAL(object2,initial_value1); + + return 0; +} + diff --git a/swap/test/std_dateorder.cpp b/swap/test/std_dateorder.cpp new file mode 100644 index 0000000..b593f6f --- /dev/null +++ b/swap/test/std_dateorder.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests swapping std::time_base::dateorder objects by means of boost::swap. +// std::time_base::dateorder is an enumerated type. It does not have an +// std::swap overload or template specialization. + +#include +#define BOOST_INCLUDE_MAIN +#include + +#include + +int test_main(int, char*[]) +{ + const std::time_base::dateorder initial_value1 = std::time_base::dmy; + const std::time_base::dateorder initial_value2 = std::time_base::mdy; + + std::time_base::dateorder object1 = initial_value1; + std::time_base::dateorder object2 = initial_value2; + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1,initial_value2); + BOOST_CHECK_EQUAL(object2,initial_value1); + + return 0; +} + diff --git a/swap/test/std_string.cpp b/swap/test/std_string.cpp new file mode 100644 index 0000000..b7d3d4d --- /dev/null +++ b/swap/test/std_string.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests swapping std::string objects by means of boost::swap. +// std::string has its own std::swap overload. + +#include +#define BOOST_INCLUDE_MAIN +#include + +#include + +int test_main(int, char*[]) +{ + const std::string initial_value1 = "one"; + const std::string initial_value2 = "two"; + + std::string object1 = initial_value1; + std::string object2 = initial_value2; + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1,initial_value2); + BOOST_CHECK_EQUAL(object2,initial_value1); + + return 0; +} + diff --git a/swap/test/std_typeinfo_ptr.cpp b/swap/test/std_typeinfo_ptr.cpp new file mode 100644 index 0000000..38e293a --- /dev/null +++ b/swap/test/std_typeinfo_ptr.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests swapping std::type_info pointers by means of boost::swap. +// There is no std::swap overload or template specialization +// for std::type_info pointers. + +#include +#define BOOST_INCLUDE_MAIN +#include + +#include + +int test_main(int, char*[]) +{ + const std::type_info * const initial_value1 = 0; + const std::type_info * const initial_value2 = &typeid(double); + + const std::type_info * ptr1 = initial_value1; + const std::type_info * ptr2 = initial_value2; + + boost::swap(ptr1,ptr2); + + BOOST_CHECK_EQUAL(ptr1,initial_value2); + BOOST_CHECK_EQUAL(ptr2,initial_value1); + + return 0; +} + diff --git a/swap/test/std_vector_of_boost.cpp b/swap/test/std_vector_of_boost.cpp new file mode 100644 index 0000000..f9c3888 --- /dev/null +++ b/swap/test/std_vector_of_boost.cpp @@ -0,0 +1,54 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests swapping std::vector objects by means of boost::swap, +// having boost::swap_test_class as vector element type. + +#include +#define BOOST_INCLUDE_MAIN +#include + +#include + +//Put test class in namespace boost +namespace boost +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace boost +namespace boost +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int test_main(int, char*[]) +{ + typedef boost::swap_test_class swap_test_class_type; + typedef std::vector vector_type; + + const vector_type::size_type initial_size1 = 1; + const vector_type::size_type initial_size2 = 2; + + vector_type object1(initial_size1); + vector_type object2(initial_size2); + + swap_test_class_type::reset(); + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1.size(),initial_size2); + BOOST_CHECK_EQUAL(object2.size(),initial_size1); + + BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0); + BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0); + + return 0; +} + diff --git a/swap/test/std_vector_of_global.cpp b/swap/test/std_vector_of_global.cpp new file mode 100644 index 0000000..ef6b52b --- /dev/null +++ b/swap/test/std_vector_of_global.cpp @@ -0,0 +1,47 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests swapping std::vector objects by means of boost::swap, +// having ::swap_test_class as vector element type. + +#include +#define BOOST_INCLUDE_MAIN +#include + +#include + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + +//Provide swap function in the global namespace +void swap(swap_test_class& left, swap_test_class& right) +{ + left.swap(right); +} + +int test_main(int, char*[]) +{ + typedef std::vector vector_type; + + const vector_type::size_type initial_size1 = 1; + const vector_type::size_type initial_size2 = 2; + + vector_type object1(initial_size1); + vector_type object2(initial_size2); + + swap_test_class::reset(); + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1.size(),initial_size2); + BOOST_CHECK_EQUAL(object2.size(),initial_size1); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(),0); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); + + return 0; +} + diff --git a/swap/test/std_vector_of_other.cpp b/swap/test/std_vector_of_other.cpp new file mode 100644 index 0000000..3834269 --- /dev/null +++ b/swap/test/std_vector_of_other.cpp @@ -0,0 +1,54 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Tests swapping std::vector objects by means of boost::swap, +// having other::swap_test_class as vector element type. + +#include +#define BOOST_INCLUDE_MAIN +#include + +#include + +//Put test class in namespace other +namespace other +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace other +namespace other +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int test_main(int, char*[]) +{ + typedef other::swap_test_class swap_test_class_type; + typedef std::vector vector_type; + + const vector_type::size_type initial_size1 = 1; + const vector_type::size_type initial_size2 = 2; + + vector_type object1(initial_size1); + vector_type object2(initial_size2); + + swap_test_class_type::reset(); + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1.size(),initial_size2); + BOOST_CHECK_EQUAL(object2.size(),initial_size1); + + BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0); + BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0); + + return 0; +} + From 62836f29285d4553a22bafd938e4b88781e8b7e5 Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Mon, 4 Aug 2008 11:21:02 +0000 Subject: [PATCH 27/30] Changed 'using std::swap;' to 'using namesapce std;' in swap_impl function to work around ADL bugs in some compilers. [SVN r47967] --- include/boost/utility/swap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp index da293ee..71cc454 100644 --- a/include/boost/utility/swap.hpp +++ b/include/boost/utility/swap.hpp @@ -20,7 +20,7 @@ namespace boost_swap_impl template void swap_impl(T& left, T& right) { - using std::swap;//use std::swap if argument dependent lookup fails + using namespace std;//use std::swap if argument dependent lookup fails swap(left,right); } From 49faf23433c14abdd068e82f21125401ca8c820a Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Mon, 4 Aug 2008 18:16:16 +0000 Subject: [PATCH 28/30] Updated copyright info. [SVN r47971] --- include/boost/utility/swap.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp index 71cc454..f42264c 100644 --- a/include/boost/utility/swap.hpp +++ b/include/boost/utility/swap.hpp @@ -1,12 +1,9 @@ -// Copyright (C) 2007, 2008 Steven Watanabe, Joseph Gauterin +// Copyright (C) 2007, 2008 Steven Watanabe, Joseph Gauterin, Niels Dekker // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // For more information, see http://www.boost.org -// -// Update: -// 29 June 2008 (Added support for built-in arrays.) Niels Dekker #ifndef BOOST_UTILITY_SWAP_HPP From 7019e18149e7df70c6c4e403d6ad648d86b4d810 Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Mon, 4 Aug 2008 18:22:10 +0000 Subject: [PATCH 29/30] Renamed 'test_adl_barrier.cpp' to 'no_ambiguity_in_boost.cpp' and altered comments to reflect new disambiguation technique. [SVN r47972] --- swap/test/Jamfile.v2 | 2 +- .../{test_adl_barrier.cpp => no_ambiguity_in_boost.cpp} | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) rename swap/test/{test_adl_barrier.cpp => no_ambiguity_in_boost.cpp} (84%) diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index d08a47a..7071837 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -28,6 +28,6 @@ test-suite utility/swap [ run std_vector_of_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run std_vector_of_global.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run std_vector_of_other.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run no_ambiguity_in_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; diff --git a/swap/test/test_adl_barrier.cpp b/swap/test/no_ambiguity_in_boost.cpp similarity index 84% rename from swap/test/test_adl_barrier.cpp rename to swap/test/no_ambiguity_in_boost.cpp index e30a1b6..17fe9d6 100644 --- a/swap/test/test_adl_barrier.cpp +++ b/swap/test/no_ambiguity_in_boost.cpp @@ -7,9 +7,10 @@ // boost::swap internally does an unqualified function call to swap. // This could have led to ambiguity or infinite recursion, when the // objects to be swapped would themselves be from the boost namespace. -// If so, boost::swap itself might be found by argument dependent lookup -// (ADL). The implementation of boost::swap resolves this issue by -// using a barrier namespace. The following test checks this "ADL barrier". +// If so, boost::swap itself might be found by argument dependent lookup. +// The implementation of boost::swap resolves this issue by giving +// boost::swap two template argumetns, thereby making it less specialized +// than std::swap. #include #define BOOST_INCLUDE_MAIN From 7e3e326faf306478a83045f9803996286e02e596 Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Mon, 4 Aug 2008 18:25:45 +0000 Subject: [PATCH 30/30] Updated documentation to remove references to the 'ADL barrier' [SVN r47973] --- swap.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/swap.html b/swap.html index e317b11..dfe9b84 100644 --- a/swap.html +++ b/swap.html @@ -1,4 +1,4 @@ -? + @@ -73,7 +73,7 @@ Joseph Gauterin - for the initial idea, implementation, tests, and documentation
  • - Steven Wanatabe - for the idea to use a barrier namespace, enabling the function to have the name 'swap' without introducing ambiguity or infinite recursion + Steven Wanatabe - for the idea to make boost::swap less specialized than std::swap, thereby allowing the function to have the name 'swap' without introducing ambiguity
  • @@ -84,7 +84,7 @@
    -

    Revised: 3 July 2008

    +

    Revised: 4 August 2008

    Copyright 2007, 2008 Joseph Gauterin. Use, modification, and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)