Index: boost/operators.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/operators.hpp,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- boost/operators.hpp 27 Feb 2005 17:28:08 -0000 1.23 +++ boost/operators.hpp 23 May 2007 22:48:42 -0000 1.24 @@ -8,6 +8,8 @@ // See http://www.boost.org/libs/utility/operators.htm for documentation. // Revision History +// 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 // correct named return value optimization (NRVO) to produce optimal // code. (Daniel Frey) @@ -90,15 +92,15 @@ namespace boost { namespace detail { +template class empty_base { + // Helmut Zeisel, empty base class optimization bug with GCC 3.0.0 #if defined(__GNUC__) && __GNUC__==3 && __GNUC_MINOR__==0 && __GNU_PATCHLEVEL__==0 -class empty_base { bool dummy; -}; -#else -class empty_base {}; #endif +}; + } // namespace detail } // namespace boost @@ -119,7 +121,7 @@ // Note that friend functions defined in a class are implicitly inline. // See the C++ std, 11.4 [class.friend] paragraph 5 -template +template > struct less_than_comparable2 : B { friend bool operator<=(const T& x, const U& y) { return !(x > y); } @@ -130,7 +132,7 @@ friend bool operator>=(const U& x, const T& y) { return !(y > x); } }; -template +template > struct less_than_comparable1 : B { friend bool operator>(const T& x, const T& y) { return y < x; } @@ -138,7 +140,7 @@ friend bool operator>=(const T& x, const T& y) { return !(x < y); } }; -template +template > struct equality_comparable2 : B { friend bool operator==(const U& y, const T& x) { return x == y; } @@ -146,7 +148,7 @@ friend bool operator!=(const T& y, const U& x) { return !(y == x); } }; -template +template > struct equality_comparable1 : B { friend bool operator!=(const T& x, const T& y) { return !(x == y); } @@ -165,7 +167,7 @@ // implementation available. #define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \ -template \ +template > \ struct NAME##2 : B \ { \ friend T operator OP( const T& lhs, const U& rhs ) \ @@ -174,33 +176,33 @@ { T nrv( rhs ); nrv OP##= lhs; return nrv; } \ }; \ \ -template \ +template > \ struct NAME##1 : B \ { \ friend T operator OP( const T& lhs, const T& rhs ) \ { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ }; -#define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \ -template \ -struct NAME##2 : B \ -{ \ - friend T operator OP( const T& lhs, const U& rhs ) \ - { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ -}; \ - \ -template \ -struct BOOST_OPERATOR2_LEFT(NAME) : B \ -{ \ - friend T operator OP( const U& lhs, const T& rhs ) \ - { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ -}; \ - \ -template \ -struct NAME##1 : B \ -{ \ - friend T operator OP( const T& lhs, const T& rhs ) \ - { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ +#define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \ +template > \ +struct NAME##2 : B \ +{ \ + friend T operator OP( const T& lhs, const U& rhs ) \ + { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ +}; \ + \ +template > \ +struct BOOST_OPERATOR2_LEFT(NAME) : B \ +{ \ + friend T operator OP( const U& lhs, const T& rhs ) \ + { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ +}; \ + \ +template > \ +struct NAME##1 : B \ +{ \ + friend T operator OP( const T& lhs, const T& rhs ) \ + { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ }; #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS) @@ -210,35 +212,35 @@ // BOOST_OPERATOR2_LEFT(NAME) only looks cool, but doesn't provide // optimization opportunities to the compiler :) -#define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \ -template \ -struct NAME##2 : B \ -{ \ - friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \ - friend T operator OP( const U& lhs, T rhs ) { return rhs OP##= lhs; } \ -}; \ - \ -template \ -struct NAME##1 : B \ -{ \ - friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \ +#define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \ +template > \ +struct NAME##2 : B \ +{ \ + friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \ + friend T operator OP( const U& lhs, T rhs ) { return rhs OP##= lhs; } \ +}; \ + \ +template > \ +struct NAME##1 : B \ +{ \ + friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \ }; #define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \ -template \ +template > \ struct NAME##2 : B \ { \ friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \ }; \ \ -template \ +template > \ struct BOOST_OPERATOR2_LEFT(NAME) : B \ { \ friend T operator OP( const U& lhs, const T& rhs ) \ { return T( lhs ) OP##= rhs; } \ }; \ \ -template \ +template > \ struct NAME##1 : B \ { \ friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \ @@ -261,7 +263,7 @@ // incrementable and decrementable contributed by Jeremy Siek -template +template > struct incrementable : B { friend T operator++(T& x, int) @@ -274,7 +276,7 @@ typedef T incrementable_type; }; -template +template > struct decrementable : B { friend T operator--(T& x, int) @@ -289,7 +291,7 @@ // Iterator operator classes (contributed by Jeremy Siek) ------------------// -template +template > struct dereferenceable : B { P operator->() const @@ -298,7 +300,7 @@ } }; -template +template > struct indexable : B { R operator[](I n) const @@ -313,14 +315,14 @@ #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS) #define BOOST_BINARY_OPERATOR( NAME, OP ) \ -template \ +template > \ struct NAME##2 : B \ { \ friend T operator OP( const T& lhs, const U& rhs ) \ { T nrv( lhs ); nrv OP##= rhs; return nrv; } \ }; \ \ -template \ +template > \ struct NAME##1 : B \ { \ friend T operator OP( const T& lhs, const T& rhs ) \ @@ -330,13 +332,13 @@ #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS) #define BOOST_BINARY_OPERATOR( NAME, OP ) \ -template \ +template > \ struct NAME##2 : B \ { \ friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \ }; \ \ -template \ +template > \ struct NAME##1 : B \ { \ friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \ @@ -349,7 +351,7 @@ #undef BOOST_BINARY_OPERATOR -template +template > struct equivalent2 : B { friend bool operator==(const T& x, const U& y) @@ -358,7 +360,7 @@ } }; -template +template > struct equivalent1 : B { friend bool operator==(const T&x, const T&y) @@ -367,7 +369,7 @@ } }; -template +template > struct partially_ordered2 : B { friend bool operator<=(const T& x, const U& y) @@ -384,7 +386,7 @@ { return (y < x) || (y == x); } }; -template +template > struct partially_ordered1 : B { friend bool operator>(const T& x, const T& y) @@ -397,161 +399,161 @@ // Combined operator classes (contributed by Daryle Walker) ----------------// -template +template > struct totally_ordered2 : less_than_comparable2 > {}; -template +template > struct totally_ordered1 : less_than_comparable1 > {}; -template +template > struct additive2 : addable2 > {}; -template +template > struct additive1 : addable1 > {}; -template +template > struct multiplicative2 : multipliable2 > {}; -template +template > struct multiplicative1 : multipliable1 > {}; -template +template > struct integer_multiplicative2 : multiplicative2 > {}; -template +template > struct integer_multiplicative1 : multiplicative1 > {}; -template +template > struct arithmetic2 : additive2 > {}; -template +template > struct arithmetic1 : additive1 > {}; -template +template > struct integer_arithmetic2 : additive2 > {}; -template +template > struct integer_arithmetic1 : additive1 > {}; -template +template > struct bitwise2 : xorable2 > > {}; -template +template > struct bitwise1 : xorable1 > > {}; -template +template > struct unit_steppable : incrementable > {}; -template +template > struct shiftable2 : left_shiftable2 > {}; -template +template > struct shiftable1 : left_shiftable1 > {}; -template +template > struct ring_operators2 : additive2 > > {}; -template +template > struct ring_operators1 : additive1 > {}; -template +template > struct ordered_ring_operators2 : ring_operators2 > {}; -template +template > struct ordered_ring_operators1 : ring_operators1 > {}; -template +template > struct field_operators2 : ring_operators2 > > {}; -template +template > struct field_operators1 : ring_operators1 > {}; -template +template > struct ordered_field_operators2 : field_operators2 > {}; -template +template > struct ordered_field_operators1 : field_operators1 > {}; -template +template > struct euclidian_ring_operators2 : ring_operators2 > > > > {}; -template +template > struct euclidian_ring_operators1 : ring_operators1 > > {}; -template +template > struct ordered_euclidian_ring_operators2 : totally_ordered2 > {}; -template +template > struct ordered_euclidian_ring_operators1 : totally_ordered1 > {}; -template +template > struct input_iteratable : equality_comparable1 > > {}; -template +template > struct output_iteratable : incrementable {}; -template +template > struct forward_iteratable : input_iteratable {}; -template +template > struct bidirectional_iteratable : forward_iteratable +template > struct random_access_iteratable : bidirectional_iteratable \ +# define BOOST_IMPORT_TEMPLATE4(template_name) \ + template > \ struct template_name : ::template_name {}; -# define BOOST_IMPORT_TEMPLATE3(template_name) \ - template \ +# define BOOST_IMPORT_TEMPLATE3(template_name) \ + template > \ struct template_name : ::template_name {}; -# define BOOST_IMPORT_TEMPLATE2(template_name) \ - template \ +# define BOOST_IMPORT_TEMPLATE2(template_name) \ + template > \ struct template_name : ::template_name {}; -# define BOOST_IMPORT_TEMPLATE1(template_name) \ - template \ +# define BOOST_IMPORT_TEMPLATE1(template_name) \ + template > \ struct template_name : ::template_name {}; # endif // BOOST_NO_USING_TEMPLATE @@ -752,7 +754,7 @@ # define BOOST_OPERATOR_TEMPLATE(template_name) \ template \ ,class O = typename is_chained_base::value \ > \ struct template_name : template_name##2 {}; \ @@ -788,7 +790,7 @@ // In this case we can only assume that template_name<> is equivalent to the // more commonly needed template_name1<> form. # define BOOST_OPERATOR_TEMPLATE(template_name) \ - template \ + template > \ struct template_name : template_name##1 {}; #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION