85 #ifndef BOOST_OPERATORS_HPP
86 #define BOOST_OPERATORS_HPP
90 #if defined(BOOST_NO_OPERATORS_IN_NAMESPACE) || defined(BOOST_USE_OPERATORS_V1)
91 #include "operators_v1.hpp"
100 #if defined(__sgi) && !defined(__GNUC__)
101 # pragma set woff 1234
104 #if BOOST_WORKAROUND(BOOST_MSVC, < 1600)
105 # pragma warning( disable : 4284 ) // complaint about return type of
106 #endif // operator-> not begin a UDT
114 namespace operators_impl
116 namespace operators_detail
128 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
131 friend bool operator<=(
const T& x,
const U& y) {
return !
static_cast<bool>(x > y); }
132 friend bool operator>=(
const T& x,
const U& y) {
return !
static_cast<bool>(x < y); }
133 friend bool operator>(
const U& x,
const T& y) {
return y < x; }
134 friend bool operator<(
const U& x,
const T& y) {
return y > x; }
135 friend bool operator<=(
const U& x,
const T& y) {
return !
static_cast<bool>(y < x); }
136 friend bool operator>=(
const U& x,
const T& y) {
return !
static_cast<bool>(y > x); }
139 template <
class T,
class B = operators_detail::empty_base<T> >
143 friend bool operator<=(
const T& x,
const T& y) {
return !
static_cast<bool>(y < x); }
144 friend bool operator>=(
const T& x,
const T& y) {
return !
static_cast<bool>(x < y); }
147 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
151 friend bool operator!=(
const U& y,
const T& x) {
return !
static_cast<bool>(x == y); }
152 friend bool operator!=(
const T& y,
const U& x) {
return !
static_cast<bool>(y == x); }
155 template <
class T,
class B = operators_detail::empty_base<T> >
158 friend bool operator!=(
const T& x,
const T& y) {
return !
static_cast<bool>(x == y); }
162 #define BOOST_OPERATOR2_LEFT(name) name##2##_##left
166 #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
173 #define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \
174 template <class T, class U, class B = operators_detail::empty_base<T> > \
177 friend T operator OP( const T& lhs, const U& rhs ) \
178 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
179 friend T operator OP( const U& lhs, const T& rhs ) \
180 { T nrv( rhs ); nrv OP##= lhs; return nrv; } \
183 template <class T, class B = operators_detail::empty_base<T> > \
186 friend T operator OP( const T& lhs, const T& rhs ) \
187 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
190 #define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \
191 template <class T, class U, class B = operators_detail::empty_base<T> > \
194 friend T operator OP( const T& lhs, const U& rhs ) \
195 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
198 template <class T, class U, class B = operators_detail::empty_base<T> > \
199 struct BOOST_OPERATOR2_LEFT(NAME) : B \
201 friend T operator OP( const U& lhs, const T& rhs ) \
202 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
205 template <class T, class B = operators_detail::empty_base<T> > \
208 friend T operator OP( const T& lhs, const T& rhs ) \
209 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
212 #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
219 #define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \
220 template <class T, class U, class B = operators_detail::empty_base<T> > \
223 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
224 friend T operator OP( const U& lhs, T rhs ) { return rhs OP##= lhs; } \
227 template <class T, class B = operators_detail::empty_base<T> > \
230 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
233 #define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \
234 template <class T, class U, class B = operators_detail::empty_base<T> > \
237 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
240 template <class T, class U, class B = operators_detail::empty_base<T> > \
241 struct BOOST_OPERATOR2_LEFT(NAME) : B \
243 friend T operator OP( const U& lhs, const T& rhs ) \
244 { return T( lhs ) OP##= rhs; } \
247 template <class T, class B = operators_detail::empty_base<T> > \
250 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
253 #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
264 #undef BOOST_BINARY_OPERATOR_COMMUTATIVE
265 #undef BOOST_BINARY_OPERATOR_NON_COMMUTATIVE
266 #undef BOOST_OPERATOR2_LEFT
270 template <
class T,
class B = operators_detail::empty_base<T> >
283 template <
class T,
class B = operators_detail::empty_base<T> >
298 template <
class T,
class P,
class B = operators_detail::empty_base<T> >
303 return &*
static_cast<const T&
>(*this);
307 template <
class T,
class I,
class R,
class B = operators_detail::empty_base<T> >
312 return *(
static_cast<const T&
>(*this) + n);
319 #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
321 #define BOOST_BINARY_OPERATOR( NAME, OP ) \
322 template <class T, class U, class B = operators_detail::empty_base<T> > \
325 friend T operator OP( const T& lhs, const U& rhs ) \
326 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
329 template <class T, class B = operators_detail::empty_base<T> > \
332 friend T operator OP( const T& lhs, const T& rhs ) \
333 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
336 #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
338 #define BOOST_BINARY_OPERATOR( NAME, OP ) \
339 template <class T, class U, class B = operators_detail::empty_base<T> > \
342 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
345 template <class T, class B = operators_detail::empty_base<T> > \
348 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
351 #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
356 #undef BOOST_BINARY_OPERATOR
358 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
363 return !
static_cast<bool>(x < y) && !static_cast<bool>(x > y);
367 template <
class T,
class B = operators_detail::empty_base<T> >
372 return !
static_cast<bool>(x < y) && !static_cast<bool>(y < x);
376 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
380 {
return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
382 {
return static_cast<bool>(x > y) ||
static_cast<bool>(x == y); }
388 {
return static_cast<bool>(y > x) ||
static_cast<bool>(y == x); }
390 {
return static_cast<bool>(y < x) || static_cast<bool>(y == x); }
393 template <
class T,
class B = operators_detail::empty_base<T> >
399 {
return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
401 {
return static_cast<bool>(y < x) || static_cast<bool>(x == y); }
406 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
409 , equality_comparable2<T, U, B
412 template <
class T,
class B = operators_detail::empty_base<T> >
415 , equality_comparable1<T, B
418 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
421 , subtractable2<T, U, B
424 template <
class T,
class B = operators_detail::empty_base<T> >
430 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
436 template <
class T,
class B = operators_detail::empty_base<T> >
442 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
448 template <
class T,
class B = operators_detail::empty_base<T> >
454 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
457 , multiplicative2<T, U, B
460 template <
class T,
class B = operators_detail::empty_base<T> >
463 , multiplicative1<T, B
466 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
469 , integer_multiplicative2<T, U, B
472 template <
class T,
class B = operators_detail::empty_base<T> >
475 , integer_multiplicative1<T, B
478 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
485 template <
class T,
class B = operators_detail::empty_base<T> >
492 template <
class T,
class B = operators_detail::empty_base<T> >
498 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
500 : left_shiftable2<T, U
501 , right_shiftable2<T, U, B
504 template <
class T,
class B = operators_detail::empty_base<T> >
507 , right_shiftable1<T, B
510 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
513 , subtractable2_left<T, U
514 , multipliable2<T, U, B
517 template <
class T,
class B = operators_detail::empty_base<T> >
523 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
526 , totally_ordered2<T, U, B
529 template <
class T,
class B = operators_detail::empty_base<T> >
532 , totally_ordered1<T, B
535 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
539 , dividable2_left<T, U, B
542 template <
class T,
class B = operators_detail::empty_base<T> >
548 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
551 , totally_ordered2<T, U, B
554 template <
class T,
class B = operators_detail::empty_base<T> >
557 , totally_ordered1<T, B
560 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
564 , dividable2_left<T, U
566 , modable2_left<T, U, B
569 template <
class T,
class B = operators_detail::empty_base<T> >
576 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
579 , euclidian_ring_operators2<T, U, B
582 template <
class T,
class B = operators_detail::empty_base<T> >
585 , euclidian_ring_operators1<T, B
588 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
592 , dividable2_left<T, U
594 , modable2_left<T, U, B
597 template <
class T,
class B = operators_detail::empty_base<T> >
604 template <
class T,
class U,
class B = operators_detail::empty_base<T> >
607 , euclidean_ring_operators2<T, U, B
610 template <
class T,
class B = operators_detail::empty_base<T> >
613 , euclidean_ring_operators1<T, B
616 template <
class T,
class P,
class B = operators_detail::empty_base<T> >
620 , dereferenceable<T, P, B
623 template <
class T,
class B = operators_detail::empty_base<T> >
628 template <
class T,
class P,
class B = operators_detail::empty_base<T> >
633 template <
class T,
class P,
class B = operators_detail::empty_base<T> >
643 template <
class T,
class P,
class D,
class R,
class B = operators_detail::empty_base<T> >
646 , less_than_comparable1<T
648 , indexable<T, D, R, B
658 namespace operators_detail
681 # define BOOST_OPERATOR_TEMPLATE4(template_name4) \
682 template<class T, class U, class V, class W, class B> \
683 struct is_chained_base< template_name4<T, U, V, W, B> > { \
684 typedef operators_detail::true_t value; \
689 # define BOOST_OPERATOR_TEMPLATE3(template_name3) \
690 template<class T, class U, class V, class B> \
691 struct is_chained_base< template_name3<T, U, V, B> > { \
692 typedef operators_detail::true_t value; \
697 # define BOOST_OPERATOR_TEMPLATE2(template_name2) \
698 template<class T, class U, class B> \
699 struct is_chained_base< template_name2<T, U, B> > { \
700 typedef operators_detail::true_t value; \
705 # define BOOST_OPERATOR_TEMPLATE1(template_name1) \
706 template<class T, class B> \
707 struct is_chained_base< template_name1<T, B> > { \
708 typedef operators_detail::true_t value; \
725 # define BOOST_OPERATOR_TEMPLATE(template_name) \
728 ,class B = operators_detail::empty_base<T> \
729 ,class O = typename is_chained_base<U>::value \
731 struct template_name; \
733 template<class T, class U, class B> \
734 struct template_name<T, U, B, operators_detail::false_t> \
735 : template_name##2<T, U, B> {}; \
737 template<class T, class U> \
738 struct template_name<T, U, operators_detail::empty_base<T>, operators_detail::true_t> \
739 : template_name##1<T, U> {}; \
741 template <class T, class B> \
742 struct template_name<T, T, B, operators_detail::false_t> \
743 : template_name##1<T, B> {}; \
745 template<class T, class U, class B, class O> \
746 struct is_chained_base< template_name<T, U, B, O> > { \
747 typedef operators_detail::true_t value; \
750 BOOST_OPERATOR_TEMPLATE2(template_name##2) \
751 BOOST_OPERATOR_TEMPLATE1(template_name##1)
801 #undef BOOST_OPERATOR_TEMPLATE
802 #undef BOOST_OPERATOR_TEMPLATE4
803 #undef BOOST_OPERATOR_TEMPLATE3
804 #undef BOOST_OPERATOR_TEMPLATE2
805 #undef BOOST_OPERATOR_TEMPLATE1
807 template <
class T,
class U>
810 , integer_arithmetic2<T,U
814 template <
class T,
class U = T>
819 , integer_arithmetic<T
829 class D = std::ptrdiff_t,
834 , std::iterator<std::input_iterator_tag, V, D, P, R
840 , std::iterator<std::output_iterator_tag, void, void, void, void
849 class D = std::ptrdiff_t,
854 , std::iterator<std::forward_iterator_tag, V, D, P, R
859 class D = std::ptrdiff_t,
864 , std::iterator<std::bidirectional_iterator_tag, V, D, P, R
869 class D = std::ptrdiff_t,
874 , std::iterator<std::random_access_iterator_tag, V, D, P, R
883 using namespace operators_impl;
887 #if defined(__sgi) && !defined(__GNUC__)
888 #pragma reset woff 1234
891 #endif // BOOST_NO_OPERATORS_IN_NAMESPACE
892 #endif // BOOST_OPERATORS_HPP