1 // Boost operators.hpp header file ----------------------------------------//
3 // (C) Copyright David Abrahams, Jeremy Siek, Daryle Walker 1999-2001.
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org/libs/utility/operators.htm for documentation.
11 // 16 Dec 10 Limit warning suppression for 4284 to older versions of VC++
12 // (Matthew Bradbury, fixes #4432)
13 // 07 Aug 08 Added "euclidean" spelling. (Daniel Frey)
14 // 03 Apr 08 Make sure "convertible to bool" is sufficient
15 // for T::operator<, etc. (Daniel Frey)
16 // 24 May 07 Changed empty_base to depend on T, see
17 // http://svn.boost.org/trac/boost/ticket/979
18 // 21 Oct 02 Modified implementation of operators to allow compilers with a
19 // correct named return value optimization (NRVO) to produce optimal
20 // code. (Daniel Frey)
21 // 02 Dec 01 Bug fixed in random_access_iteratable. (Helmut Zeisel)
22 // 28 Sep 01 Factored out iterator operator groups. (Daryle Walker)
23 // 27 Aug 01 'left' form for non commutative operators added;
24 // additional classes for groups of related operators added;
25 // workaround for empty base class optimization
26 // bug of GCC 3.0 (Helmut Zeisel)
27 // 25 Jun 01 output_iterator_helper changes: removed default template
28 // parameters, added support for self-proxying, additional
29 // documentation and tests (Aleksey Gurtovoy)
30 // 29 May 01 Added operator classes for << and >>. Added input and output
31 // iterator helper classes. Added classes to connect equality and
32 // relational operators. Added classes for groups of related
33 // operators. Reimplemented example operator and iterator helper
34 // classes in terms of the new groups. (Daryle Walker, with help
35 // from Alexy Gurtovoy)
36 // 11 Feb 01 Fixed bugs in the iterator helpers which prevented explicitly
37 // supplied arguments from actually being used (Dave Abrahams)
38 // 04 Jul 00 Fixed NO_OPERATORS_IN_NAMESPACE bugs, major cleanup and
39 // refactoring of compiler workarounds, additional documentation
40 // (Alexy Gurtovoy and Mark Rodgers with some help and prompting from
42 // 28 Jun 00 General cleanup and integration of bugfixes from Mark Rodgers and
43 // Jeremy Siek (Dave Abrahams)
44 // 20 Jun 00 Changes to accommodate Borland C++Builder 4 and Borland C++ 5.5
46 // 20 Jun 00 Minor fixes to the prior revision (Aleksey Gurtovoy)
47 // 10 Jun 00 Support for the base class chaining technique was added
48 // (Aleksey Gurtovoy). See documentation and the comments below
50 // 12 Dec 99 Initial version with iterator operators (Jeremy Siek)
51 // 18 Nov 99 Change name "divideable" to "dividable", remove unnecessary
52 // specializations of dividable, subtractable, modable (Ed Brey)
53 // 17 Nov 99 Add comments (Beman Dawes)
54 // Remove unnecessary specialization of operators<> (Ed Brey)
55 // 15 Nov 99 Fix less_than_comparable<T,U> second operand type for first two
56 // operators.(Beman Dawes)
57 // 12 Nov 99 Add operators templates (Ed Brey)
58 // 11 Nov 99 Add single template parameter version for compilers without
59 // partial specialization (Beman Dawes)
60 // 10 Nov 99 Initial version
63 // An additional optional template parameter was added to most of
64 // operator templates to support the base class chaining technique (see
65 // documentation for the details). Unfortunately, a straightforward
66 // implementation of this change would have broken compatibility with the
67 // previous version of the library by making it impossible to use the same
68 // template name (e.g. 'addable') for both the 1- and 2-argument versions of
69 // an operator template. This implementation solves the backward-compatibility
70 // issue at the cost of some simplicity.
72 // One of the complications is an existence of special auxiliary class template
73 // 'is_chained_base<>' (see 'detail' namespace below), which is used
74 // to determine whether its template parameter is a library's operator template
75 // or not. You have to specialize 'is_chained_base<>' for each new
76 // operator template you add to the library.
78 // However, most of the non-trivial implementation details are hidden behind
79 // several local macros defined below, and as soon as you understand them,
80 // you understand the whole library implementation.
82 #ifndef BOOST_OPERATORS_HPP
83 #define BOOST_OPERATORS_HPP
85 #include <boost/config.hpp>
86 #include <boost/iterator.hpp>
87 #include <boost/detail/workaround.hpp>
89 #if defined(__sgi) && !defined(__GNUC__)
90 # pragma set woff 1234
93 #if BOOST_WORKAROUND(BOOST_MSVC, < 1600)
94 # pragma warning( disable : 4284 ) // complaint about return type of
95 #endif // operator-> not begin a UDT
100 template <typename T> class empty_base {
102 // Helmut Zeisel, empty base class optimization bug with GCC 3.0.0
103 #if defined(__GNUC__) && __GNUC__==3 && __GNUC_MINOR__==0 && __GNU_PATCHLEVEL__==0
109 } // namespace detail
112 // In this section we supply the xxxx1 and xxxx2 forms of the operator
113 // templates, which are explicitly targeted at the 1-type-argument and
114 // 2-type-argument operator forms, respectively. Some compilers get confused
115 // when inline friend functions are overloaded in namespaces other than the
116 // global namespace. When BOOST_NO_OPERATORS_IN_NAMESPACE is defined, all of
117 // these templates must go in the global namespace.
119 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
124 // Basic operator classes (contributed by Dave Abrahams) ------------------//
126 // Note that friend functions defined in a class are implicitly inline.
127 // See the C++ std, 11.4 [class.friend] paragraph 5
129 template <class T, class U, class B = ::boost::detail::empty_base<T> >
130 struct less_than_comparable2 : B
132 friend bool operator<=(const T& x, const U& y) { return !static_cast<bool>(x > y); }
133 friend bool operator>=(const T& x, const U& y) { return !static_cast<bool>(x < y); }
134 friend bool operator>(const U& x, const T& y) { return y < x; }
135 friend bool operator<(const U& x, const T& y) { return y > x; }
136 friend bool operator<=(const U& x, const T& y) { return !static_cast<bool>(y < x); }
137 friend bool operator>=(const U& x, const T& y) { return !static_cast<bool>(y > x); }
140 template <class T, class B = ::boost::detail::empty_base<T> >
141 struct less_than_comparable1 : B
143 friend bool operator>(const T& x, const T& y) { return y < x; }
144 friend bool operator<=(const T& x, const T& y) { return !static_cast<bool>(y < x); }
145 friend bool operator>=(const T& x, const T& y) { return !static_cast<bool>(x < y); }
148 template <class T, class U, class B = ::boost::detail::empty_base<T> >
149 struct equality_comparable2 : B
151 friend bool operator==(const U& y, const T& x) { return x == y; }
152 friend bool operator!=(const U& y, const T& x) { return !static_cast<bool>(x == y); }
153 friend bool operator!=(const T& y, const U& x) { return !static_cast<bool>(y == x); }
156 template <class T, class B = ::boost::detail::empty_base<T> >
157 struct equality_comparable1 : B
159 friend bool operator!=(const T& x, const T& y) { return !static_cast<bool>(x == y); }
162 // A macro which produces "name_2left" from "name".
163 #define BOOST_OPERATOR2_LEFT(name) name##2##_##left
165 // NRVO-friendly implementation (contributed by Daniel Frey) ---------------//
167 #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
169 // This is the optimal implementation for ISO/ANSI C++,
170 // but it requires the compiler to implement the NRVO.
171 // If the compiler has no NRVO, this is the best symmetric
172 // implementation available.
174 #define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \
175 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
178 friend T operator OP( const T& lhs, const U& rhs ) \
179 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
180 friend T operator OP( const U& lhs, const T& rhs ) \
181 { T nrv( rhs ); nrv OP##= lhs; return nrv; } \
184 template <class T, class B = ::boost::detail::empty_base<T> > \
187 friend T operator OP( const T& lhs, const T& rhs ) \
188 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
191 #define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \
192 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
195 friend T operator OP( const T& lhs, const U& rhs ) \
196 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
199 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
200 struct BOOST_OPERATOR2_LEFT(NAME) : B \
202 friend T operator OP( const U& lhs, const T& rhs ) \
203 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
206 template <class T, class B = ::boost::detail::empty_base<T> > \
209 friend T operator OP( const T& lhs, const T& rhs ) \
210 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
213 #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
215 // For compilers without NRVO the following code is optimal, but not
216 // symmetric! Note that the implementation of
217 // BOOST_OPERATOR2_LEFT(NAME) only looks cool, but doesn't provide
218 // optimization opportunities to the compiler :)
220 #define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \
221 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
224 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
225 friend T operator OP( const U& lhs, T rhs ) { return rhs OP##= lhs; } \
228 template <class T, class B = ::boost::detail::empty_base<T> > \
231 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
234 #define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \
235 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
238 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
241 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
242 struct BOOST_OPERATOR2_LEFT(NAME) : B \
244 friend T operator OP( const U& lhs, const T& rhs ) \
245 { return T( lhs ) OP##= rhs; } \
248 template <class T, class B = ::boost::detail::empty_base<T> > \
251 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
254 #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
256 BOOST_BINARY_OPERATOR_COMMUTATIVE( multipliable, * )
257 BOOST_BINARY_OPERATOR_COMMUTATIVE( addable, + )
258 BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( subtractable, - )
259 BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( dividable, / )
260 BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( modable, % )
261 BOOST_BINARY_OPERATOR_COMMUTATIVE( xorable, ^ )
262 BOOST_BINARY_OPERATOR_COMMUTATIVE( andable, & )
263 BOOST_BINARY_OPERATOR_COMMUTATIVE( orable, | )
265 #undef BOOST_BINARY_OPERATOR_COMMUTATIVE
266 #undef BOOST_BINARY_OPERATOR_NON_COMMUTATIVE
267 #undef BOOST_OPERATOR2_LEFT
269 // incrementable and decrementable contributed by Jeremy Siek
271 template <class T, class B = ::boost::detail::empty_base<T> >
272 struct incrementable : B
274 friend T operator++(T& x, int)
276 incrementable_type nrv(x);
280 private: // The use of this typedef works around a Borland bug
281 typedef T incrementable_type;
284 template <class T, class B = ::boost::detail::empty_base<T> >
285 struct decrementable : B
287 friend T operator--(T& x, int)
289 decrementable_type nrv(x);
293 private: // The use of this typedef works around a Borland bug
294 typedef T decrementable_type;
297 // Iterator operator classes (contributed by Jeremy Siek) ------------------//
299 template <class T, class P, class B = ::boost::detail::empty_base<T> >
300 struct dereferenceable : B
304 return &*static_cast<const T&>(*this);
308 template <class T, class I, class R, class B = ::boost::detail::empty_base<T> >
311 R operator[](I n) const
313 return *(static_cast<const T&>(*this) + n);
317 // More operator classes (contributed by Daryle Walker) --------------------//
318 // (NRVO-friendly implementation contributed by Daniel Frey) ---------------//
320 #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
322 #define BOOST_BINARY_OPERATOR( NAME, OP ) \
323 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
326 friend T operator OP( const T& lhs, const U& rhs ) \
327 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
330 template <class T, class B = ::boost::detail::empty_base<T> > \
333 friend T operator OP( const T& lhs, const T& rhs ) \
334 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
337 #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
339 #define BOOST_BINARY_OPERATOR( NAME, OP ) \
340 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
343 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
346 template <class T, class B = ::boost::detail::empty_base<T> > \
349 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
352 #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
354 BOOST_BINARY_OPERATOR( left_shiftable, << )
355 BOOST_BINARY_OPERATOR( right_shiftable, >> )
357 #undef BOOST_BINARY_OPERATOR
359 template <class T, class U, class B = ::boost::detail::empty_base<T> >
360 struct equivalent2 : B
362 friend bool operator==(const T& x, const U& y)
364 return !static_cast<bool>(x < y) && !static_cast<bool>(x > y);
368 template <class T, class B = ::boost::detail::empty_base<T> >
369 struct equivalent1 : B
371 friend bool operator==(const T&x, const T&y)
373 return !static_cast<bool>(x < y) && !static_cast<bool>(y < x);
377 template <class T, class U, class B = ::boost::detail::empty_base<T> >
378 struct partially_ordered2 : B
380 friend bool operator<=(const T& x, const U& y)
381 { return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
382 friend bool operator>=(const T& x, const U& y)
383 { return static_cast<bool>(x > y) || static_cast<bool>(x == y); }
384 friend bool operator>(const U& x, const T& y)
386 friend bool operator<(const U& x, const T& y)
388 friend bool operator<=(const U& x, const T& y)
389 { return static_cast<bool>(y > x) || static_cast<bool>(y == x); }
390 friend bool operator>=(const U& x, const T& y)
391 { return static_cast<bool>(y < x) || static_cast<bool>(y == x); }
394 template <class T, class B = ::boost::detail::empty_base<T> >
395 struct partially_ordered1 : B
397 friend bool operator>(const T& x, const T& y)
399 friend bool operator<=(const T& x, const T& y)
400 { return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
401 friend bool operator>=(const T& x, const T& y)
402 { return static_cast<bool>(y < x) || static_cast<bool>(x == y); }
405 // Combined operator classes (contributed by Daryle Walker) ----------------//
407 template <class T, class U, class B = ::boost::detail::empty_base<T> >
408 struct totally_ordered2
409 : less_than_comparable2<T, U
410 , equality_comparable2<T, U, B
413 template <class T, class B = ::boost::detail::empty_base<T> >
414 struct totally_ordered1
415 : less_than_comparable1<T
416 , equality_comparable1<T, B
419 template <class T, class U, class B = ::boost::detail::empty_base<T> >
422 , subtractable2<T, U, B
425 template <class T, class B = ::boost::detail::empty_base<T> >
431 template <class T, class U, class B = ::boost::detail::empty_base<T> >
432 struct multiplicative2
437 template <class T, class B = ::boost::detail::empty_base<T> >
438 struct multiplicative1
443 template <class T, class U, class B = ::boost::detail::empty_base<T> >
444 struct integer_multiplicative2
445 : multiplicative2<T, U
449 template <class T, class B = ::boost::detail::empty_base<T> >
450 struct integer_multiplicative1
455 template <class T, class U, class B = ::boost::detail::empty_base<T> >
458 , multiplicative2<T, U, B
461 template <class T, class B = ::boost::detail::empty_base<T> >
464 , multiplicative1<T, B
467 template <class T, class U, class B = ::boost::detail::empty_base<T> >
468 struct integer_arithmetic2
470 , integer_multiplicative2<T, U, B
473 template <class T, class B = ::boost::detail::empty_base<T> >
474 struct integer_arithmetic1
476 , integer_multiplicative1<T, B
479 template <class T, class U, class B = ::boost::detail::empty_base<T> >
486 template <class T, class B = ::boost::detail::empty_base<T> >
493 template <class T, class B = ::boost::detail::empty_base<T> >
494 struct unit_steppable
499 template <class T, class U, class B = ::boost::detail::empty_base<T> >
501 : left_shiftable2<T, U
502 , right_shiftable2<T, U, B
505 template <class T, class B = ::boost::detail::empty_base<T> >
508 , right_shiftable1<T, B
511 template <class T, class U, class B = ::boost::detail::empty_base<T> >
512 struct ring_operators2
514 , subtractable2_left<T, U
515 , multipliable2<T, U, B
518 template <class T, class B = ::boost::detail::empty_base<T> >
519 struct ring_operators1
524 template <class T, class U, class B = ::boost::detail::empty_base<T> >
525 struct ordered_ring_operators2
526 : ring_operators2<T, U
527 , totally_ordered2<T, U, B
530 template <class T, class B = ::boost::detail::empty_base<T> >
531 struct ordered_ring_operators1
533 , totally_ordered1<T, B
536 template <class T, class U, class B = ::boost::detail::empty_base<T> >
537 struct field_operators2
538 : ring_operators2<T, U
540 , dividable2_left<T, U, B
543 template <class T, class B = ::boost::detail::empty_base<T> >
544 struct field_operators1
549 template <class T, class U, class B = ::boost::detail::empty_base<T> >
550 struct ordered_field_operators2
551 : field_operators2<T, U
552 , totally_ordered2<T, U, B
555 template <class T, class B = ::boost::detail::empty_base<T> >
556 struct ordered_field_operators1
558 , totally_ordered1<T, B
561 template <class T, class U, class B = ::boost::detail::empty_base<T> >
562 struct euclidian_ring_operators2
563 : ring_operators2<T, U
565 , dividable2_left<T, U
567 , modable2_left<T, U, B
570 template <class T, class B = ::boost::detail::empty_base<T> >
571 struct euclidian_ring_operators1
577 template <class T, class U, class B = ::boost::detail::empty_base<T> >
578 struct ordered_euclidian_ring_operators2
579 : totally_ordered2<T, U
580 , euclidian_ring_operators2<T, U, B
583 template <class T, class B = ::boost::detail::empty_base<T> >
584 struct ordered_euclidian_ring_operators1
586 , euclidian_ring_operators1<T, B
589 template <class T, class U, class B = ::boost::detail::empty_base<T> >
590 struct euclidean_ring_operators2
591 : ring_operators2<T, U
593 , dividable2_left<T, U
595 , modable2_left<T, U, B
598 template <class T, class B = ::boost::detail::empty_base<T> >
599 struct euclidean_ring_operators1
605 template <class T, class U, class B = ::boost::detail::empty_base<T> >
606 struct ordered_euclidean_ring_operators2
607 : totally_ordered2<T, U
608 , euclidean_ring_operators2<T, U, B
611 template <class T, class B = ::boost::detail::empty_base<T> >
612 struct ordered_euclidean_ring_operators1
614 , euclidean_ring_operators1<T, B
617 template <class T, class P, class B = ::boost::detail::empty_base<T> >
618 struct input_iteratable
619 : equality_comparable1<T
621 , dereferenceable<T, P, B
624 template <class T, class B = ::boost::detail::empty_base<T> >
625 struct output_iteratable
629 template <class T, class P, class B = ::boost::detail::empty_base<T> >
630 struct forward_iteratable
631 : input_iteratable<T, P, B
634 template <class T, class P, class B = ::boost::detail::empty_base<T> >
635 struct bidirectional_iteratable
636 : forward_iteratable<T, P
640 // To avoid repeated derivation from equality_comparable,
641 // which is an indirect base class of bidirectional_iterable,
642 // random_access_iteratable must not be derived from totally_ordered1
643 // but from less_than_comparable1 only. (Helmut Zeisel, 02-Dec-2001)
644 template <class T, class P, class D, class R, class B = ::boost::detail::empty_base<T> >
645 struct random_access_iteratable
646 : bidirectional_iteratable<T, P
647 , less_than_comparable1<T
649 , indexable<T, D, R, B
652 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
654 #endif // BOOST_NO_OPERATORS_IN_NAMESPACE
657 // BOOST_IMPORT_TEMPLATE1 .. BOOST_IMPORT_TEMPLATE4 -
659 // When BOOST_NO_OPERATORS_IN_NAMESPACE is defined we need a way to import an
660 // operator template into the boost namespace. BOOST_IMPORT_TEMPLATE1 is used
661 // for one-argument forms of operator templates; BOOST_IMPORT_TEMPLATE2 for
662 // two-argument forms. Note that these macros expect to be invoked from within
665 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
667 // The template is already in boost so we have nothing to do.
668 # define BOOST_IMPORT_TEMPLATE4(template_name)
669 # define BOOST_IMPORT_TEMPLATE3(template_name)
670 # define BOOST_IMPORT_TEMPLATE2(template_name)
671 # define BOOST_IMPORT_TEMPLATE1(template_name)
673 #else // BOOST_NO_OPERATORS_IN_NAMESPACE
675 # ifndef BOOST_NO_USING_TEMPLATE
677 // Bring the names in with a using-declaration
678 // to avoid stressing the compiler.
679 # define BOOST_IMPORT_TEMPLATE4(template_name) using ::template_name;
680 # define BOOST_IMPORT_TEMPLATE3(template_name) using ::template_name;
681 # define BOOST_IMPORT_TEMPLATE2(template_name) using ::template_name;
682 # define BOOST_IMPORT_TEMPLATE1(template_name) using ::template_name;
686 // Otherwise, because a Borland C++ 5.5 bug prevents a using declaration
687 // from working, we are forced to use inheritance for that compiler.
688 # define BOOST_IMPORT_TEMPLATE4(template_name) \
689 template <class T, class U, class V, class W, class B = ::boost::detail::empty_base<T> > \
690 struct template_name : ::template_name<T, U, V, W, B> {};
692 # define BOOST_IMPORT_TEMPLATE3(template_name) \
693 template <class T, class U, class V, class B = ::boost::detail::empty_base<T> > \
694 struct template_name : ::template_name<T, U, V, B> {};
696 # define BOOST_IMPORT_TEMPLATE2(template_name) \
697 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
698 struct template_name : ::template_name<T, U, B> {};
700 # define BOOST_IMPORT_TEMPLATE1(template_name) \
701 template <class T, class B = ::boost::detail::empty_base<T> > \
702 struct template_name : ::template_name<T, B> {};
704 # endif // BOOST_NO_USING_TEMPLATE
706 #endif // BOOST_NO_OPERATORS_IN_NAMESPACE
709 // Here's where we put it all together, defining the xxxx forms of the templates
710 // in namespace boost. We also define specializations of is_chained_base<> for
711 // the xxxx, xxxx1, and xxxx2 templates, importing them into boost:: as
714 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
716 // is_chained_base<> - a traits class used to distinguish whether an operator
717 // template argument is being used for base class chaining, or is specifying a
718 // 2nd argument type.
721 // A type parameter is used instead of a plain bool because Borland's compiler
722 // didn't cope well with the more obvious non-type template parameter.
726 } // namespace detail
728 // Unspecialized version assumes that most types are not being used for base
729 // class chaining. We specialize for the operator templates defined in this
731 template<class T> struct is_chained_base {
732 typedef ::boost::detail::false_t value;
737 // Import a 4-type-argument operator template into boost (if necessary) and
738 // provide a specialization of 'is_chained_base<>' for it.
739 # define BOOST_OPERATOR_TEMPLATE4(template_name4) \
740 BOOST_IMPORT_TEMPLATE4(template_name4) \
741 template<class T, class U, class V, class W, class B> \
742 struct is_chained_base< ::boost::template_name4<T, U, V, W, B> > { \
743 typedef ::boost::detail::true_t value; \
746 // Import a 3-type-argument operator template into boost (if necessary) and
747 // provide a specialization of 'is_chained_base<>' for it.
748 # define BOOST_OPERATOR_TEMPLATE3(template_name3) \
749 BOOST_IMPORT_TEMPLATE3(template_name3) \
750 template<class T, class U, class V, class B> \
751 struct is_chained_base< ::boost::template_name3<T, U, V, B> > { \
752 typedef ::boost::detail::true_t value; \
755 // Import a 2-type-argument operator template into boost (if necessary) and
756 // provide a specialization of 'is_chained_base<>' for it.
757 # define BOOST_OPERATOR_TEMPLATE2(template_name2) \
758 BOOST_IMPORT_TEMPLATE2(template_name2) \
759 template<class T, class U, class B> \
760 struct is_chained_base< ::boost::template_name2<T, U, B> > { \
761 typedef ::boost::detail::true_t value; \
764 // Import a 1-type-argument operator template into boost (if necessary) and
765 // provide a specialization of 'is_chained_base<>' for it.
766 # define BOOST_OPERATOR_TEMPLATE1(template_name1) \
767 BOOST_IMPORT_TEMPLATE1(template_name1) \
768 template<class T, class B> \
769 struct is_chained_base< ::boost::template_name1<T, B> > { \
770 typedef ::boost::detail::true_t value; \
773 // BOOST_OPERATOR_TEMPLATE(template_name) defines template_name<> such that it
774 // can be used for specifying both 1-argument and 2-argument forms. Requires the
775 // existence of two previously defined class templates named '<template_name>1'
776 // and '<template_name>2' which must implement the corresponding 1- and 2-
779 // The template type parameter O == is_chained_base<U>::value is used to
780 // distinguish whether the 2nd argument to <template_name> is being used for
781 // base class chaining from another boost operator template or is describing a
782 // 2nd operand type. O == true_t only when U is actually an another operator
783 // template from the library. Partial specialization is used to select an
784 // implementation in terms of either '<template_name>1' or '<template_name>2'.
787 # define BOOST_OPERATOR_TEMPLATE(template_name) \
790 ,class B = ::boost::detail::empty_base<T> \
791 ,class O = typename is_chained_base<U>::value \
793 struct template_name : template_name##2<T, U, B> {}; \
795 template<class T, class U, class B> \
796 struct template_name<T, U, B, ::boost::detail::true_t> \
797 : template_name##1<T, U> {}; \
799 template <class T, class B> \
800 struct template_name<T, T, B, ::boost::detail::false_t> \
801 : template_name##1<T, B> {}; \
803 template<class T, class U, class B, class O> \
804 struct is_chained_base< ::boost::template_name<T, U, B, O> > { \
805 typedef ::boost::detail::true_t value; \
808 BOOST_OPERATOR_TEMPLATE2(template_name##2) \
809 BOOST_OPERATOR_TEMPLATE1(template_name##1)
812 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
814 # define BOOST_OPERATOR_TEMPLATE4(template_name4) \
815 BOOST_IMPORT_TEMPLATE4(template_name4)
816 # define BOOST_OPERATOR_TEMPLATE3(template_name3) \
817 BOOST_IMPORT_TEMPLATE3(template_name3)
818 # define BOOST_OPERATOR_TEMPLATE2(template_name2) \
819 BOOST_IMPORT_TEMPLATE2(template_name2)
820 # define BOOST_OPERATOR_TEMPLATE1(template_name1) \
821 BOOST_IMPORT_TEMPLATE1(template_name1)
823 // In this case we can only assume that template_name<> is equivalent to the
824 // more commonly needed template_name1<> form.
825 # define BOOST_OPERATOR_TEMPLATE(template_name) \
826 template <class T, class B = ::boost::detail::empty_base<T> > \
827 struct template_name : template_name##1<T, B> {};
829 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
833 BOOST_OPERATOR_TEMPLATE(less_than_comparable)
834 BOOST_OPERATOR_TEMPLATE(equality_comparable)
835 BOOST_OPERATOR_TEMPLATE(multipliable)
836 BOOST_OPERATOR_TEMPLATE(addable)
837 BOOST_OPERATOR_TEMPLATE(subtractable)
838 BOOST_OPERATOR_TEMPLATE2(subtractable2_left)
839 BOOST_OPERATOR_TEMPLATE(dividable)
840 BOOST_OPERATOR_TEMPLATE2(dividable2_left)
841 BOOST_OPERATOR_TEMPLATE(modable)
842 BOOST_OPERATOR_TEMPLATE2(modable2_left)
843 BOOST_OPERATOR_TEMPLATE(xorable)
844 BOOST_OPERATOR_TEMPLATE(andable)
845 BOOST_OPERATOR_TEMPLATE(orable)
847 BOOST_OPERATOR_TEMPLATE1(incrementable)
848 BOOST_OPERATOR_TEMPLATE1(decrementable)
850 BOOST_OPERATOR_TEMPLATE2(dereferenceable)
851 BOOST_OPERATOR_TEMPLATE3(indexable)
853 BOOST_OPERATOR_TEMPLATE(left_shiftable)
854 BOOST_OPERATOR_TEMPLATE(right_shiftable)
855 BOOST_OPERATOR_TEMPLATE(equivalent)
856 BOOST_OPERATOR_TEMPLATE(partially_ordered)
858 BOOST_OPERATOR_TEMPLATE(totally_ordered)
859 BOOST_OPERATOR_TEMPLATE(additive)
860 BOOST_OPERATOR_TEMPLATE(multiplicative)
861 BOOST_OPERATOR_TEMPLATE(integer_multiplicative)
862 BOOST_OPERATOR_TEMPLATE(arithmetic)
863 BOOST_OPERATOR_TEMPLATE(integer_arithmetic)
864 BOOST_OPERATOR_TEMPLATE(bitwise)
865 BOOST_OPERATOR_TEMPLATE1(unit_steppable)
866 BOOST_OPERATOR_TEMPLATE(shiftable)
867 BOOST_OPERATOR_TEMPLATE(ring_operators)
868 BOOST_OPERATOR_TEMPLATE(ordered_ring_operators)
869 BOOST_OPERATOR_TEMPLATE(field_operators)
870 BOOST_OPERATOR_TEMPLATE(ordered_field_operators)
871 BOOST_OPERATOR_TEMPLATE(euclidian_ring_operators)
872 BOOST_OPERATOR_TEMPLATE(ordered_euclidian_ring_operators)
873 BOOST_OPERATOR_TEMPLATE(euclidean_ring_operators)
874 BOOST_OPERATOR_TEMPLATE(ordered_euclidean_ring_operators)
875 BOOST_OPERATOR_TEMPLATE2(input_iteratable)
876 BOOST_OPERATOR_TEMPLATE1(output_iteratable)
877 BOOST_OPERATOR_TEMPLATE2(forward_iteratable)
878 BOOST_OPERATOR_TEMPLATE2(bidirectional_iteratable)
879 BOOST_OPERATOR_TEMPLATE4(random_access_iteratable)
881 #undef BOOST_OPERATOR_TEMPLATE
882 #undef BOOST_OPERATOR_TEMPLATE4
883 #undef BOOST_OPERATOR_TEMPLATE3
884 #undef BOOST_OPERATOR_TEMPLATE2
885 #undef BOOST_OPERATOR_TEMPLATE1
886 #undef BOOST_IMPORT_TEMPLATE1
887 #undef BOOST_IMPORT_TEMPLATE2
888 #undef BOOST_IMPORT_TEMPLATE3
889 #undef BOOST_IMPORT_TEMPLATE4
891 // The following 'operators' classes can only be used portably if the derived class
892 // declares ALL of the required member operators.
893 template <class T, class U>
895 : totally_ordered2<T,U
896 , integer_arithmetic2<T,U
900 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
901 template <class T, class U = T>
902 struct operators : operators2<T, U> {};
904 template <class T> struct operators<T, T>
906 template <class T> struct operators
909 , integer_arithmetic<T
914 // Iterator helper classes (contributed by Jeremy Siek) -------------------//
915 // (Input and output iterator helpers contributed by Daryle Walker) -------//
916 // (Changed to use combined operator classes by Daryle Walker) ------------//
919 class D = std::ptrdiff_t,
922 struct input_iterator_helper
923 : input_iteratable<T, P
924 , boost::iterator<std::input_iterator_tag, V, D, P, R
928 struct output_iterator_helper
929 : output_iteratable<T
930 , boost::iterator<std::output_iterator_tag, void, void, void, void
933 T& operator*() { return static_cast<T&>(*this); }
934 T& operator++() { return static_cast<T&>(*this); }
939 class D = std::ptrdiff_t,
942 struct forward_iterator_helper
943 : forward_iteratable<T, P
944 , boost::iterator<std::forward_iterator_tag, V, D, P, R
949 class D = std::ptrdiff_t,
952 struct bidirectional_iterator_helper
953 : bidirectional_iteratable<T, P
954 , boost::iterator<std::bidirectional_iterator_tag, V, D, P, R
959 class D = std::ptrdiff_t,
962 struct random_access_iterator_helper
963 : random_access_iteratable<T, P, D, R
964 , boost::iterator<std::random_access_iterator_tag, V, D, P, R
967 friend D requires_difference_operator(const T& x, const T& y) {
970 }; // random_access_iterator_helper
974 #if defined(__sgi) && !defined(__GNUC__)
975 #pragma reset woff 1234
978 #endif // BOOST_OPERATORS_HPP