1 // Boost operators.hpp header file ----------------------------------------//
3 // (C) Copyright David Abrahams, Jeremy Siek, and Daryle Walker 1999-2001.
4 // Permission to copy, use, modify, sell and distribute this software is
5 // granted provided this copyright notice appears in all copies. This
6 // software is provided "as is" without express or implied warranty, and
7 // with no claim as to its suitability for any purpose.
9 // See http://www.boost.org/libs/utility/operators.htm for documentation.
12 // 21 Oct 02 Modified implementation of operators to allow compilers with a
13 // correct named return value optimization (NRVO) to produce optimal
14 // code. (Daniel Frey)
15 // 02 Dec 01 Bug fixed in random_access_iteratable. (Helmut Zeisel)
16 // 28 Sep 01 Factored out iterator operator groups. (Daryle Walker)
17 // 27 Aug 01 'left' form for non commutative operators added;
18 // additional classes for groups of related operators added;
19 // workaround for empty base class optimization
20 // bug of GCC 3.0 (Helmut Zeisel)
21 // 25 Jun 01 output_iterator_helper changes: removed default template
22 // parameters, added support for self-proxying, additional
23 // documentation and tests (Aleksey Gurtovoy)
24 // 29 May 01 Added operator classes for << and >>. Added input and output
25 // iterator helper classes. Added classes to connect equality and
26 // relational operators. Added classes for groups of related
27 // operators. Reimplemented example operator and iterator helper
28 // classes in terms of the new groups. (Daryle Walker, with help
29 // from Alexy Gurtovoy)
30 // 11 Feb 01 Fixed bugs in the iterator helpers which prevented explicitly
31 // supplied arguments from actually being used (Dave Abrahams)
32 // 04 Jul 00 Fixed NO_OPERATORS_IN_NAMESPACE bugs, major cleanup and
33 // refactoring of compiler workarounds, additional documentation
34 // (Alexy Gurtovoy and Mark Rodgers with some help and prompting from
36 // 28 Jun 00 General cleanup and integration of bugfixes from Mark Rodgers and
37 // Jeremy Siek (Dave Abrahams)
38 // 20 Jun 00 Changes to accommodate Borland C++Builder 4 and Borland C++ 5.5
40 // 20 Jun 00 Minor fixes to the prior revision (Aleksey Gurtovoy)
41 // 10 Jun 00 Support for the base class chaining technique was added
42 // (Aleksey Gurtovoy). See documentation and the comments below
44 // 12 Dec 99 Initial version with iterator operators (Jeremy Siek)
45 // 18 Nov 99 Change name "divideable" to "dividable", remove unnecessary
46 // specializations of dividable, subtractable, modable (Ed Brey)
47 // 17 Nov 99 Add comments (Beman Dawes)
48 // Remove unnecessary specialization of operators<> (Ed Brey)
49 // 15 Nov 99 Fix less_than_comparable<T,U> second operand type for first two
50 // operators.(Beman Dawes)
51 // 12 Nov 99 Add operators templates (Ed Brey)
52 // 11 Nov 99 Add single template parameter version for compilers without
53 // partial specialization (Beman Dawes)
54 // 10 Nov 99 Initial version
57 // An additional optional template parameter was added to most of
58 // operator templates to support the base class chaining technique (see
59 // documentation for the details). Unfortunately, a straightforward
60 // implementation of this change would have broken compatibility with the
61 // previous version of the library by making it impossible to use the same
62 // template name (e.g. 'addable') for both the 1- and 2-argument versions of
63 // an operator template. This implementation solves the backward-compatibility
64 // issue at the cost of some simplicity.
66 // One of the complications is an existence of special auxiliary class template
67 // 'is_chained_base<>' (see 'detail' namespace below), which is used
68 // to determine whether its template parameter is a library's operator template
69 // or not. You have to specialize 'is_chained_base<>' for each new
70 // operator template you add to the library.
72 // However, most of the non-trivial implementation details are hidden behind
73 // several local macros defined below, and as soon as you understand them,
74 // you understand the whole library implementation.
76 #ifndef BOOST_OPERATORS_HPP
77 #define BOOST_OPERATORS_HPP
79 #include <boost/config.hpp>
80 #include <boost/iterator.hpp>
81 #include <boost/detail/workaround.hpp>
83 #if defined(__sgi) && !defined(__GNUC__)
84 # pragma set woff 1234
87 #if defined(BOOST_MSVC)
88 # pragma warning( disable : 4284 ) // complaint about return type of
89 #endif // operator-> not begin a UDT
94 // Helmut Zeisel, empty base class optimization bug with GCC 3.0.0
95 #if defined(__GNUC__) && __GNUC__==3 && __GNUC_MINOR__==0 && __GNU_PATCHLEVEL__==0
103 } // namespace detail
106 // In this section we supply the xxxx1 and xxxx2 forms of the operator
107 // templates, which are explicitly targeted at the 1-type-argument and
108 // 2-type-argument operator forms, respectively. Some compilers get confused
109 // when inline friend functions are overloaded in namespaces other than the
110 // global namespace. When BOOST_NO_OPERATORS_IN_NAMESPACE is defined, all of
111 // these templates must go in the global namespace.
113 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
118 // Basic operator classes (contributed by Dave Abrahams) ------------------//
120 // Note that friend functions defined in a class are implicitly inline.
121 // See the C++ std, 11.4 [class.friend] paragraph 5
123 template <class T, class U, class B = ::boost::detail::empty_base>
124 struct less_than_comparable2 : B
126 friend bool operator<=(const T& x, const U& y) { return !(x > y); }
127 friend bool operator>=(const T& x, const U& y) { return !(x < y); }
128 friend bool operator>(const U& x, const T& y) { return y < x; }
129 friend bool operator<(const U& x, const T& y) { return y > x; }
130 friend bool operator<=(const U& x, const T& y) { return !(y < x); }
131 friend bool operator>=(const U& x, const T& y) { return !(y > x); }
134 template <class T, class B = ::boost::detail::empty_base>
135 struct less_than_comparable1 : B
137 friend bool operator>(const T& x, const T& y) { return y < x; }
138 friend bool operator<=(const T& x, const T& y) { return !(y < x); }
139 friend bool operator>=(const T& x, const T& y) { return !(x < y); }
142 template <class T, class U, class B = ::boost::detail::empty_base>
143 struct equality_comparable2 : B
145 friend bool operator==(const U& y, const T& x) { return x == y; }
146 friend bool operator!=(const U& y, const T& x) { return !(x == y); }
147 friend bool operator!=(const T& y, const U& x) { return !(y == x); }
150 template <class T, class B = ::boost::detail::empty_base>
151 struct equality_comparable1 : B
153 friend bool operator!=(const T& x, const T& y) { return !(x == y); }
156 // A macro which produces "name_2left" from "name".
157 #define BOOST_OPERATOR2_LEFT(name) name##2##_##left
159 // NRVO-friendly implementation (contributed by Daniel Frey) ---------------//
161 #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
163 // This is the optimal implementation for ISO/ANSI C++,
164 // but it requires the compiler to implement the NRVO.
165 // If the compiler has no NRVO, this is the best symmetric
166 // implementation available.
168 #define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \
169 template <class T, class U, class B = ::boost::detail::empty_base> \
172 friend T operator OP( const T& lhs, const U& rhs ) \
173 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
174 friend T operator OP( const U& lhs, const T& rhs ) \
175 { T nrv( rhs ); nrv OP##= lhs; return nrv; } \
178 template <class T, class B = ::boost::detail::empty_base> \
181 friend T operator OP( const T& lhs, const T& rhs ) \
182 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
185 #define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \
186 template <class T, class U, class B = ::boost::detail::empty_base> \
189 friend T operator OP( const T& lhs, const U& rhs ) \
190 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
193 template <class T, class U, class B = ::boost::detail::empty_base> \
194 struct BOOST_OPERATOR2_LEFT(NAME) : B \
196 friend T operator OP( const U& lhs, const T& rhs ) \
197 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
200 template <class T, class B = ::boost::detail::empty_base> \
203 friend T operator OP( const T& lhs, const T& rhs ) \
204 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
207 #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
209 // For compilers without NRVO the following code is optimal, but not
210 // symmetric! Note that the implementation of
211 // BOOST_OPERATOR2_LEFT(NAME) only looks cool, but doesn't provide
212 // optimization opportunities to the compiler :)
214 #define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \
215 template <class T, class U, class B = ::boost::detail::empty_base> \
218 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
219 friend T operator OP( const U& lhs, T rhs ) { return rhs OP##= lhs; } \
222 template <class T, class B = ::boost::detail::empty_base> \
225 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
228 #define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \
229 template <class T, class U, class B = ::boost::detail::empty_base> \
232 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
235 template <class T, class U, class B = ::boost::detail::empty_base> \
236 struct BOOST_OPERATOR2_LEFT(NAME) : B \
238 friend T operator OP( const U& lhs, const T& rhs ) \
239 { return T( lhs ) OP##= rhs; } \
242 template <class T, class B = ::boost::detail::empty_base> \
245 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
248 #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
250 BOOST_BINARY_OPERATOR_COMMUTATIVE( multipliable, * )
251 BOOST_BINARY_OPERATOR_COMMUTATIVE( addable, + )
252 BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( subtractable, - )
253 BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( dividable, / )
254 BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( modable, % )
255 BOOST_BINARY_OPERATOR_COMMUTATIVE( xorable, ^ )
256 BOOST_BINARY_OPERATOR_COMMUTATIVE( andable, & )
257 BOOST_BINARY_OPERATOR_COMMUTATIVE( orable, | )
259 #undef BOOST_BINARY_OPERATOR_COMMUTATIVE
260 #undef BOOST_BINARY_OPERATOR_NON_COMMUTATIVE
261 #undef BOOST_OPERATOR2_LEFT
263 // incrementable and decrementable contributed by Jeremy Siek
265 template <class T, class B = ::boost::detail::empty_base>
266 struct incrementable : B
268 friend T operator++(T& x, int)
270 incrementable_type nrv(x);
274 private: // The use of this typedef works around a Borland bug
275 typedef T incrementable_type;
278 template <class T, class B = ::boost::detail::empty_base>
279 struct decrementable : B
281 friend T operator--(T& x, int)
283 decrementable_type nrv(x);
287 private: // The use of this typedef works around a Borland bug
288 typedef T decrementable_type;
291 // Iterator operator classes (contributed by Jeremy Siek) ------------------//
293 template <class T, class P, class B = ::boost::detail::empty_base>
294 struct dereferenceable : B
298 return &*static_cast<const T&>(*this);
302 template <class T, class I, class R, class B = ::boost::detail::empty_base>
305 R operator[](I n) const
307 return *(static_cast<const T&>(*this) + n);
311 // More operator classes (contributed by Daryle Walker) --------------------//
312 // (NRVO-friendly implementation contributed by Daniel Frey) ---------------//
314 #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
316 #define BOOST_BINARY_OPERATOR( NAME, OP ) \
317 template <class T, class U, class B = ::boost::detail::empty_base> \
320 friend T operator OP( const T& lhs, const U& rhs ) \
321 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
324 template <class T, class B = ::boost::detail::empty_base> \
327 friend T operator OP( const T& lhs, const T& rhs ) \
328 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
331 #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
333 #define BOOST_BINARY_OPERATOR( NAME, OP ) \
334 template <class T, class U, class B = ::boost::detail::empty_base> \
337 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
340 template <class T, class B = ::boost::detail::empty_base> \
343 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
346 #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
348 BOOST_BINARY_OPERATOR( left_shiftable, << )
349 BOOST_BINARY_OPERATOR( right_shiftable, >> )
351 #undef BOOST_BINARY_OPERATOR
353 template <class T, class U, class B = ::boost::detail::empty_base>
354 struct equivalent2 : B
356 friend bool operator==(const T& x, const U& y)
358 return !(x < y) && !(x > y);
362 template <class T, class B = ::boost::detail::empty_base>
363 struct equivalent1 : B
365 friend bool operator==(const T&x, const T&y)
367 return !(x < y) && !(y < x);
371 template <class T, class U, class B = ::boost::detail::empty_base>
372 struct partially_ordered2 : B
374 friend bool operator<=(const T& x, const U& y)
375 { return (x < y) || (x == y); }
376 friend bool operator>=(const T& x, const U& y)
377 { return (x > y) || (x == y); }
378 friend bool operator>(const U& x, const T& y)
380 friend bool operator<(const U& x, const T& y)
382 friend bool operator<=(const U& x, const T& y)
383 { return (y > x) || (y == x); }
384 friend bool operator>=(const U& x, const T& y)
385 { return (y < x) || (y == x); }
388 template <class T, class B = ::boost::detail::empty_base>
389 struct partially_ordered1 : B
391 friend bool operator>(const T& x, const T& y)
393 friend bool operator<=(const T& x, const T& y)
394 { return (x < y) || (x == y); }
395 friend bool operator>=(const T& x, const T& y)
396 { return (y < x) || (x == y); }
399 // Combined operator classes (contributed by Daryle Walker) ----------------//
401 template <class T, class U, class B = ::boost::detail::empty_base>
402 struct totally_ordered2
403 : less_than_comparable2<T, U
404 , equality_comparable2<T, U, B
407 template <class T, class B = ::boost::detail::empty_base>
408 struct totally_ordered1
409 : less_than_comparable1<T
410 , equality_comparable1<T, B
413 template <class T, class U, class B = ::boost::detail::empty_base>
416 , subtractable2<T, U, B
419 template <class T, class B = ::boost::detail::empty_base>
425 template <class T, class U, class B = ::boost::detail::empty_base>
426 struct multiplicative2
431 template <class T, class B = ::boost::detail::empty_base>
432 struct multiplicative1
437 template <class T, class U, class B = ::boost::detail::empty_base>
438 struct integer_multiplicative2
439 : multiplicative2<T, U
443 template <class T, class B = ::boost::detail::empty_base>
444 struct integer_multiplicative1
449 template <class T, class U, class B = ::boost::detail::empty_base>
452 , multiplicative2<T, U, B
455 template <class T, class B = ::boost::detail::empty_base>
458 , multiplicative1<T, B
461 template <class T, class U, class B = ::boost::detail::empty_base>
462 struct integer_arithmetic2
464 , integer_multiplicative2<T, U, B
467 template <class T, class B = ::boost::detail::empty_base>
468 struct integer_arithmetic1
470 , integer_multiplicative1<T, B
473 template <class T, class U, class B = ::boost::detail::empty_base>
480 template <class T, class B = ::boost::detail::empty_base>
487 template <class T, class B = ::boost::detail::empty_base>
488 struct unit_steppable
493 template <class T, class U, class B = ::boost::detail::empty_base>
495 : left_shiftable2<T, U
496 , right_shiftable2<T, U, B
499 template <class T, class B = ::boost::detail::empty_base>
502 , right_shiftable1<T, B
505 template <class T, class U, class B = ::boost::detail::empty_base>
506 struct ring_operators2
508 , subtractable2_left<T, U
509 , multipliable2<T, U, B
512 template <class T, class B = ::boost::detail::empty_base>
513 struct ring_operators1
518 template <class T, class U, class B = ::boost::detail::empty_base>
519 struct ordered_ring_operators2
520 : ring_operators2<T, U
521 , totally_ordered2<T, U, B
524 template <class T, class B = ::boost::detail::empty_base>
525 struct ordered_ring_operators1
527 , totally_ordered1<T, B
530 template <class T, class U, class B = ::boost::detail::empty_base>
531 struct field_operators2
532 : ring_operators2<T, U
534 , dividable2_left<T, U, B
537 template <class T, class B = ::boost::detail::empty_base>
538 struct field_operators1
543 template <class T, class U, class B = ::boost::detail::empty_base>
544 struct ordered_field_operators2
545 : field_operators2<T, U
546 , totally_ordered2<T, U, B
549 template <class T, class B = ::boost::detail::empty_base>
550 struct ordered_field_operators1
552 , totally_ordered1<T, B
555 template <class T, class U, class B = ::boost::detail::empty_base>
556 struct euclidian_ring_operators2
557 : ring_operators2<T, U
559 , dividable2_left<T, U
561 , modable2_left<T, U, B
564 template <class T, class B = ::boost::detail::empty_base>
565 struct euclidian_ring_operators1
571 template <class T, class U, class B = ::boost::detail::empty_base>
572 struct ordered_euclidian_ring_operators2
573 : totally_ordered2<T, U
574 , euclidian_ring_operators2<T, U, B
577 template <class T, class B = ::boost::detail::empty_base>
578 struct ordered_euclidian_ring_operators1
580 , euclidian_ring_operators1<T, B
583 template <class T, class P, class B = ::boost::detail::empty_base>
584 struct input_iteratable
585 : equality_comparable1<T
587 , dereferenceable<T, P, B
590 template <class T, class B = ::boost::detail::empty_base>
591 struct output_iteratable
595 template <class T, class P, class B = ::boost::detail::empty_base>
596 struct forward_iteratable
597 : input_iteratable<T, P, B
600 template <class T, class P, class B = ::boost::detail::empty_base>
601 struct bidirectional_iteratable
602 : forward_iteratable<T, P
606 // To avoid repeated derivation from equality_comparable,
607 // which is an indirect base class of bidirectional_iterable,
608 // random_access_iteratable must not be derived from totally_ordered1
609 // but from less_than_comparable1 only. (Helmut Zeisel, 02-Dec-2001)
610 template <class T, class P, class D, class R, class B = ::boost::detail::empty_base>
611 struct random_access_iteratable
612 : bidirectional_iteratable<T, P
613 , less_than_comparable1<T
615 , indexable<T, D, R, B
618 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
620 #endif // BOOST_NO_OPERATORS_IN_NAMESPACE
623 // BOOST_IMPORT_TEMPLATE1 .. BOOST_IMPORT_TEMPLATE4 -
625 // When BOOST_NO_OPERATORS_IN_NAMESPACE is defined we need a way to import an
626 // operator template into the boost namespace. BOOST_IMPORT_TEMPLATE1 is used
627 // for one-argument forms of operator templates; BOOST_IMPORT_TEMPLATE2 for
628 // two-argument forms. Note that these macros expect to be invoked from within
631 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
633 // The template is already in boost so we have nothing to do.
634 # define BOOST_IMPORT_TEMPLATE4(template_name)
635 # define BOOST_IMPORT_TEMPLATE3(template_name)
636 # define BOOST_IMPORT_TEMPLATE2(template_name)
637 # define BOOST_IMPORT_TEMPLATE1(template_name)
639 #else // BOOST_NO_OPERATORS_IN_NAMESPACE
641 # ifndef BOOST_NO_USING_TEMPLATE
643 // Bring the names in with a using-declaration
644 // to avoid stressing the compiler.
645 # define BOOST_IMPORT_TEMPLATE4(template_name) using ::template_name;
646 # define BOOST_IMPORT_TEMPLATE3(template_name) using ::template_name;
647 # define BOOST_IMPORT_TEMPLATE2(template_name) using ::template_name;
648 # define BOOST_IMPORT_TEMPLATE1(template_name) using ::template_name;
652 // Otherwise, because a Borland C++ 5.5 bug prevents a using declaration
653 // from working, we are forced to use inheritance for that compiler.
654 # define BOOST_IMPORT_TEMPLATE4(template_name) \
655 template <class T, class U, class V, class W, class B = ::boost::detail::empty_base> \
656 struct template_name : ::template_name<T, U, V, W, B> {};
658 # define BOOST_IMPORT_TEMPLATE3(template_name) \
659 template <class T, class U, class V, class B = ::boost::detail::empty_base> \
660 struct template_name : ::template_name<T, U, V, B> {};
662 # define BOOST_IMPORT_TEMPLATE2(template_name) \
663 template <class T, class U, class B = ::boost::detail::empty_base> \
664 struct template_name : ::template_name<T, U, B> {};
666 # define BOOST_IMPORT_TEMPLATE1(template_name) \
667 template <class T, class B = ::boost::detail::empty_base> \
668 struct template_name : ::template_name<T, B> {};
670 # endif // BOOST_NO_USING_TEMPLATE
672 #endif // BOOST_NO_OPERATORS_IN_NAMESPACE
675 // Here's where we put it all together, defining the xxxx forms of the templates
676 // in namespace boost. We also define specializations of is_chained_base<> for
677 // the xxxx, xxxx1, and xxxx2 templates, importing them into boost:: as
680 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
682 // is_chained_base<> - a traits class used to distinguish whether an operator
683 // template argument is being used for base class chaining, or is specifying a
684 // 2nd argument type.
687 // A type parameter is used instead of a plain bool because Borland's compiler
688 // didn't cope well with the more obvious non-type template parameter.
692 } // namespace detail
694 // Unspecialized version assumes that most types are not being used for base
695 // class chaining. We specialize for the operator templates defined in this
697 template<class T> struct is_chained_base {
698 typedef ::boost::detail::false_t value;
703 // Import a 4-type-argument operator template into boost (if neccessary) and
704 // provide a specialization of 'is_chained_base<>' for it.
705 # define BOOST_OPERATOR_TEMPLATE4(template_name4) \
706 BOOST_IMPORT_TEMPLATE4(template_name4) \
707 template<class T, class U, class V, class W, class B> \
708 struct is_chained_base< ::boost::template_name4<T, U, V, W, B> > { \
709 typedef ::boost::detail::true_t value; \
712 // Import a 3-type-argument operator template into boost (if neccessary) and
713 // provide a specialization of 'is_chained_base<>' for it.
714 # define BOOST_OPERATOR_TEMPLATE3(template_name3) \
715 BOOST_IMPORT_TEMPLATE3(template_name3) \
716 template<class T, class U, class V, class B> \
717 struct is_chained_base< ::boost::template_name3<T, U, V, B> > { \
718 typedef ::boost::detail::true_t value; \
721 // Import a 2-type-argument operator template into boost (if neccessary) and
722 // provide a specialization of 'is_chained_base<>' for it.
723 # define BOOST_OPERATOR_TEMPLATE2(template_name2) \
724 BOOST_IMPORT_TEMPLATE2(template_name2) \
725 template<class T, class U, class B> \
726 struct is_chained_base< ::boost::template_name2<T, U, B> > { \
727 typedef ::boost::detail::true_t value; \
730 // Import a 1-type-argument operator template into boost (if neccessary) and
731 // provide a specialization of 'is_chained_base<>' for it.
732 # define BOOST_OPERATOR_TEMPLATE1(template_name1) \
733 BOOST_IMPORT_TEMPLATE1(template_name1) \
734 template<class T, class B> \
735 struct is_chained_base< ::boost::template_name1<T, B> > { \
736 typedef ::boost::detail::true_t value; \
739 // BOOST_OPERATOR_TEMPLATE(template_name) defines template_name<> such that it
740 // can be used for specifying both 1-argument and 2-argument forms. Requires the
741 // existence of two previously defined class templates named '<template_name>1'
742 // and '<template_name>2' which must implement the corresponding 1- and 2-
745 // The template type parameter O == is_chained_base<U>::value is used to
746 // distinguish whether the 2nd argument to <template_name> is being used for
747 // base class chaining from another boost operator template or is describing a
748 // 2nd operand type. O == true_t only when U is actually an another operator
749 // template from the library. Partial specialization is used to select an
750 // implementation in terms of either '<template_name>1' or '<template_name>2'.
753 # define BOOST_OPERATOR_TEMPLATE(template_name) \
756 ,class B = ::boost::detail::empty_base \
757 ,class O = typename is_chained_base<U>::value \
759 struct template_name : template_name##2<T, U, B> {}; \
761 template<class T, class U, class B> \
762 struct template_name<T, U, B, ::boost::detail::true_t> \
763 : template_name##1<T, U> {}; \
765 template <class T, class B> \
766 struct template_name<T, T, B, ::boost::detail::false_t> \
767 : template_name##1<T, B> {}; \
769 template<class T, class U, class B, class O> \
770 struct is_chained_base< ::boost::template_name<T, U, B, O> > { \
771 typedef ::boost::detail::true_t value; \
774 BOOST_OPERATOR_TEMPLATE2(template_name##2) \
775 BOOST_OPERATOR_TEMPLATE1(template_name##1)
778 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
780 # define BOOST_OPERATOR_TEMPLATE4(template_name4) \
781 BOOST_IMPORT_TEMPLATE4(template_name4)
782 # define BOOST_OPERATOR_TEMPLATE3(template_name3) \
783 BOOST_IMPORT_TEMPLATE3(template_name3)
784 # define BOOST_OPERATOR_TEMPLATE2(template_name2) \
785 BOOST_IMPORT_TEMPLATE2(template_name2)
786 # define BOOST_OPERATOR_TEMPLATE1(template_name1) \
787 BOOST_IMPORT_TEMPLATE1(template_name1)
789 // In this case we can only assume that template_name<> is equivalent to the
790 // more commonly needed template_name1<> form.
791 # define BOOST_OPERATOR_TEMPLATE(template_name) \
792 template <class T, class B = ::boost::detail::empty_base> \
793 struct template_name : template_name##1<T, B> {};
795 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
799 BOOST_OPERATOR_TEMPLATE(less_than_comparable)
800 BOOST_OPERATOR_TEMPLATE(equality_comparable)
801 BOOST_OPERATOR_TEMPLATE(multipliable)
802 BOOST_OPERATOR_TEMPLATE(addable)
803 BOOST_OPERATOR_TEMPLATE(subtractable)
804 BOOST_OPERATOR_TEMPLATE2(subtractable2_left)
805 BOOST_OPERATOR_TEMPLATE(dividable)
806 BOOST_OPERATOR_TEMPLATE2(dividable2_left)
807 BOOST_OPERATOR_TEMPLATE(modable)
808 BOOST_OPERATOR_TEMPLATE2(modable2_left)
809 BOOST_OPERATOR_TEMPLATE(xorable)
810 BOOST_OPERATOR_TEMPLATE(andable)
811 BOOST_OPERATOR_TEMPLATE(orable)
813 BOOST_OPERATOR_TEMPLATE1(incrementable)
814 BOOST_OPERATOR_TEMPLATE1(decrementable)
816 BOOST_OPERATOR_TEMPLATE2(dereferenceable)
817 BOOST_OPERATOR_TEMPLATE3(indexable)
819 BOOST_OPERATOR_TEMPLATE(left_shiftable)
820 BOOST_OPERATOR_TEMPLATE(right_shiftable)
821 BOOST_OPERATOR_TEMPLATE(equivalent)
822 BOOST_OPERATOR_TEMPLATE(partially_ordered)
824 BOOST_OPERATOR_TEMPLATE(totally_ordered)
825 BOOST_OPERATOR_TEMPLATE(additive)
826 BOOST_OPERATOR_TEMPLATE(multiplicative)
827 BOOST_OPERATOR_TEMPLATE(integer_multiplicative)
828 BOOST_OPERATOR_TEMPLATE(arithmetic)
829 BOOST_OPERATOR_TEMPLATE(integer_arithmetic)
830 BOOST_OPERATOR_TEMPLATE(bitwise)
831 BOOST_OPERATOR_TEMPLATE1(unit_steppable)
832 BOOST_OPERATOR_TEMPLATE(shiftable)
833 BOOST_OPERATOR_TEMPLATE(ring_operators)
834 BOOST_OPERATOR_TEMPLATE(ordered_ring_operators)
835 BOOST_OPERATOR_TEMPLATE(field_operators)
836 BOOST_OPERATOR_TEMPLATE(ordered_field_operators)
837 BOOST_OPERATOR_TEMPLATE(euclidian_ring_operators)
838 BOOST_OPERATOR_TEMPLATE(ordered_euclidian_ring_operators)
839 BOOST_OPERATOR_TEMPLATE2(input_iteratable)
840 BOOST_OPERATOR_TEMPLATE1(output_iteratable)
841 BOOST_OPERATOR_TEMPLATE2(forward_iteratable)
842 BOOST_OPERATOR_TEMPLATE2(bidirectional_iteratable)
843 BOOST_OPERATOR_TEMPLATE4(random_access_iteratable)
845 #undef BOOST_OPERATOR_TEMPLATE
846 #undef BOOST_OPERATOR_TEMPLATE4
847 #undef BOOST_OPERATOR_TEMPLATE3
848 #undef BOOST_OPERATOR_TEMPLATE2
849 #undef BOOST_OPERATOR_TEMPLATE1
850 #undef BOOST_IMPORT_TEMPLATE1
851 #undef BOOST_IMPORT_TEMPLATE2
852 #undef BOOST_IMPORT_TEMPLATE3
853 #undef BOOST_IMPORT_TEMPLATE4
855 // The following 'operators' classes can only be used portably if the derived class
856 // declares ALL of the required member operators.
857 template <class T, class U>
859 : totally_ordered2<T,U
860 , integer_arithmetic2<T,U
864 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
865 template <class T, class U = T>
866 struct operators : operators2<T, U> {};
868 template <class T> struct operators<T, T>
870 template <class T> struct operators
873 , integer_arithmetic<T
878 // Iterator helper classes (contributed by Jeremy Siek) -------------------//
879 // (Input and output iterator helpers contributed by Daryle Walker) -------//
880 // (Changed to use combined operator classes by Daryle Walker) ------------//
883 class D = std::ptrdiff_t,
886 struct input_iterator_helper
887 : input_iteratable<T, P
888 , boost::iterator<std::input_iterator_tag, V, D, P, R
892 struct output_iterator_helper
893 : output_iteratable<T
894 , boost::iterator<std::output_iterator_tag, void, void, void, void
897 T& operator*() { return static_cast<T&>(*this); }
898 T& operator++() { return static_cast<T&>(*this); }
903 class D = std::ptrdiff_t,
906 struct forward_iterator_helper
907 : forward_iteratable<T, P
908 , boost::iterator<std::forward_iterator_tag, V, D, P, R
913 class D = std::ptrdiff_t,
916 struct bidirectional_iterator_helper
917 : bidirectional_iteratable<T, P
918 , boost::iterator<std::bidirectional_iterator_tag, V, D, P, R
923 class D = std::ptrdiff_t,
926 struct random_access_iterator_helper
927 : random_access_iteratable<T, P, D, R
928 , boost::iterator<std::random_access_iterator_tag, V, D, P, R
931 friend D requires_difference_operator(const T& x, const T& y) {
934 }; // random_access_iterator_helper
938 #if defined(__sgi) && !defined(__GNUC__)
939 #pragma reset woff 1234
942 #endif // BOOST_OPERATORS_HPP