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 // 22 Feb 16 Preserve old work-arounds. (Daniel Frey)
12 // 16 Dec 10 Limit warning suppression for 4284 to older versions of VC++
13 // (Matthew Bradbury, fixes #4432)
14 // 07 Aug 08 Added "euclidean" spelling. (Daniel Frey)
15 // 03 Apr 08 Make sure "convertible to bool" is sufficient
16 // for T::operator<, etc. (Daniel Frey)
17 // 24 May 07 Changed empty_base to depend on T, see
18 // http://svn.boost.org/trac/boost/ticket/979
19 // 21 Oct 02 Modified implementation of operators to allow compilers with a
20 // correct named return value optimization (NRVO) to produce optimal
21 // code. (Daniel Frey)
22 // 02 Dec 01 Bug fixed in random_access_iteratable. (Helmut Zeisel)
23 // 28 Sep 01 Factored out iterator operator groups. (Daryle Walker)
24 // 27 Aug 01 'left' form for non commutative operators added;
25 // additional classes for groups of related operators added;
26 // workaround for empty base class optimization
27 // bug of GCC 3.0 (Helmut Zeisel)
28 // 25 Jun 01 output_iterator_helper changes: removed default template
29 // parameters, added support for self-proxying, additional
30 // documentation and tests (Aleksey Gurtovoy)
31 // 29 May 01 Added operator classes for << and >>. Added input and output
32 // iterator helper classes. Added classes to connect equality and
33 // relational operators. Added classes for groups of related
34 // operators. Reimplemented example operator and iterator helper
35 // classes in terms of the new groups. (Daryle Walker, with help
36 // from Alexy Gurtovoy)
37 // 11 Feb 01 Fixed bugs in the iterator helpers which prevented explicitly
38 // supplied arguments from actually being used (Dave Abrahams)
39 // 04 Jul 00 Fixed NO_OPERATORS_IN_NAMESPACE bugs, major cleanup and
40 // refactoring of compiler workarounds, additional documentation
41 // (Alexy Gurtovoy and Mark Rodgers with some help and prompting from
43 // 28 Jun 00 General cleanup and integration of bugfixes from Mark Rodgers and
44 // Jeremy Siek (Dave Abrahams)
45 // 20 Jun 00 Changes to accommodate Borland C++Builder 4 and Borland C++ 5.5
47 // 20 Jun 00 Minor fixes to the prior revision (Aleksey Gurtovoy)
48 // 10 Jun 00 Support for the base class chaining technique was added
49 // (Aleksey Gurtovoy). See documentation and the comments below
51 // 12 Dec 99 Initial version with iterator operators (Jeremy Siek)
52 // 18 Nov 99 Change name "divideable" to "dividable", remove unnecessary
53 // specializations of dividable, subtractable, modable (Ed Brey)
54 // 17 Nov 99 Add comments (Beman Dawes)
55 // Remove unnecessary specialization of operators<> (Ed Brey)
56 // 15 Nov 99 Fix less_than_comparable<T,U> second operand type for first two
57 // operators.(Beman Dawes)
58 // 12 Nov 99 Add operators templates (Ed Brey)
59 // 11 Nov 99 Add single template parameter version for compilers without
60 // partial specialization (Beman Dawes)
61 // 10 Nov 99 Initial version
64 // An additional optional template parameter was added to most of
65 // operator templates to support the base class chaining technique (see
66 // documentation for the details). Unfortunately, a straightforward
67 // implementation of this change would have broken compatibility with the
68 // previous version of the library by making it impossible to use the same
69 // template name (e.g. 'addable') for both the 1- and 2-argument versions of
70 // an operator template. This implementation solves the backward-compatibility
71 // issue at the cost of some simplicity.
73 // One of the complications is an existence of special auxiliary class template
74 // 'is_chained_base<>' (see 'detail' namespace below), which is used
75 // to determine whether its template parameter is a library's operator template
76 // or not. You have to specialize 'is_chained_base<>' for each new
77 // operator template you add to the library.
79 // However, most of the non-trivial implementation details are hidden behind
80 // several local macros defined below, and as soon as you understand them,
81 // you understand the whole library implementation.
83 #ifndef BOOST_OPERATORS_V1_HPP
84 #define BOOST_OPERATORS_V1_HPP
89 #include <boost/config.hpp>
90 #include <boost/detail/workaround.hpp>
92 #if defined(__sgi) && !defined(__GNUC__)
93 # pragma set woff 1234
96 #if BOOST_WORKAROUND(BOOST_MSVC, < 1600)
97 # pragma warning( disable : 4284 ) // complaint about return type of
98 #endif // operator-> not begin a UDT
103 template <typename T> class empty_base {};
105 } // namespace detail
108 // In this section we supply the xxxx1 and xxxx2 forms of the operator
109 // templates, which are explicitly targeted at the 1-type-argument and
110 // 2-type-argument operator forms, respectively. Some compilers get confused
111 // when inline friend functions are overloaded in namespaces other than the
112 // global namespace. When BOOST_NO_OPERATORS_IN_NAMESPACE is defined, all of
113 // these templates must go in the global namespace.
115 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
120 // Basic operator classes (contributed by Dave Abrahams) ------------------//
122 // Note that friend functions defined in a class are implicitly inline.
123 // See the C++ std, 11.4 [class.friend] paragraph 5
125 template <class T, class U, class B = ::boost::detail::empty_base<T> >
126 struct less_than_comparable2 : B
128 friend bool operator<=(const T& x, const U& y) { return !static_cast<bool>(x > y); }
129 friend bool operator>=(const T& x, const U& y) { return !static_cast<bool>(x < y); }
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; }
132 friend bool operator<=(const U& x, const T& y) { return !static_cast<bool>(y < x); }
133 friend bool operator>=(const U& x, const T& y) { return !static_cast<bool>(y > x); }
136 template <class T, class B = ::boost::detail::empty_base<T> >
137 struct less_than_comparable1 : B
139 friend bool operator>(const T& x, const T& y) { return y < x; }
140 friend bool operator<=(const T& x, const T& y) { return !static_cast<bool>(y < x); }
141 friend bool operator>=(const T& x, const T& y) { return !static_cast<bool>(x < y); }
144 template <class T, class U, class B = ::boost::detail::empty_base<T> >
145 struct equality_comparable2 : B
147 friend bool operator==(const U& y, const T& x) { return x == y; }
148 friend bool operator!=(const U& y, const T& x) { return !static_cast<bool>(x == y); }
149 friend bool operator!=(const T& y, const U& x) { return !static_cast<bool>(y == x); }
152 template <class T, class B = ::boost::detail::empty_base<T> >
153 struct equality_comparable1 : B
155 friend bool operator!=(const T& x, const T& y) { return !static_cast<bool>(x == y); }
158 // A macro which produces "name_2left" from "name".
159 #define BOOST_OPERATOR2_LEFT(name) name##2##_##left
161 // NRVO-friendly implementation (contributed by Daniel Frey) ---------------//
163 #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
165 // This is the optimal implementation for ISO/ANSI C++,
166 // but it requires the compiler to implement the NRVO.
167 // If the compiler has no NRVO, this is the best symmetric
168 // implementation available.
170 #define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \
171 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
174 friend T operator OP( const T& lhs, const U& rhs ) \
175 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
176 friend T operator OP( const U& lhs, const T& rhs ) \
177 { T nrv( rhs ); nrv OP##= lhs; return nrv; } \
180 template <class T, class B = ::boost::detail::empty_base<T> > \
183 friend T operator OP( const T& lhs, const T& rhs ) \
184 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
187 #define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \
188 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
191 friend T operator OP( const T& lhs, const U& rhs ) \
192 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
195 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
196 struct BOOST_OPERATOR2_LEFT(NAME) : B \
198 friend T operator OP( const U& lhs, const T& rhs ) \
199 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
202 template <class T, class B = ::boost::detail::empty_base<T> > \
205 friend T operator OP( const T& lhs, const T& rhs ) \
206 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
209 #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
211 // For compilers without NRVO the following code is optimal, but not
212 // symmetric! Note that the implementation of
213 // BOOST_OPERATOR2_LEFT(NAME) only looks cool, but doesn't provide
214 // optimization opportunities to the compiler :)
216 #define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP ) \
217 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
220 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
221 friend T operator OP( const U& lhs, T rhs ) { return rhs OP##= lhs; } \
224 template <class T, class B = ::boost::detail::empty_base<T> > \
227 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
230 #define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP ) \
231 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
234 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
237 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
238 struct BOOST_OPERATOR2_LEFT(NAME) : B \
240 friend T operator OP( const U& lhs, const T& rhs ) \
241 { return T( lhs ) OP##= rhs; } \
244 template <class T, class B = ::boost::detail::empty_base<T> > \
247 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
250 #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
252 BOOST_BINARY_OPERATOR_COMMUTATIVE( multipliable, * )
253 BOOST_BINARY_OPERATOR_COMMUTATIVE( addable, + )
254 BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( subtractable, - )
255 BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( dividable, / )
256 BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( modable, % )
257 BOOST_BINARY_OPERATOR_COMMUTATIVE( xorable, ^ )
258 BOOST_BINARY_OPERATOR_COMMUTATIVE( andable, & )
259 BOOST_BINARY_OPERATOR_COMMUTATIVE( orable, | )
261 #undef BOOST_BINARY_OPERATOR_COMMUTATIVE
262 #undef BOOST_BINARY_OPERATOR_NON_COMMUTATIVE
263 #undef BOOST_OPERATOR2_LEFT
265 // incrementable and decrementable contributed by Jeremy Siek
267 template <class T, class B = ::boost::detail::empty_base<T> >
268 struct incrementable : B
270 friend T operator++(T& x, int)
272 incrementable_type nrv(x);
276 private: // The use of this typedef works around a Borland bug
277 typedef T incrementable_type;
280 template <class T, class B = ::boost::detail::empty_base<T> >
281 struct decrementable : B
283 friend T operator--(T& x, int)
285 decrementable_type nrv(x);
289 private: // The use of this typedef works around a Borland bug
290 typedef T decrementable_type;
293 // Iterator operator classes (contributed by Jeremy Siek) ------------------//
295 template <class T, class P, class B = ::boost::detail::empty_base<T> >
296 struct dereferenceable : B
300 return &*static_cast<const T&>(*this);
304 template <class T, class I, class R, class B = ::boost::detail::empty_base<T> >
307 R operator[](I n) const
309 return *(static_cast<const T&>(*this) + n);
313 // More operator classes (contributed by Daryle Walker) --------------------//
314 // (NRVO-friendly implementation contributed by Daniel Frey) ---------------//
316 #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
318 #define BOOST_BINARY_OPERATOR( NAME, OP ) \
319 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
322 friend T operator OP( const T& lhs, const U& rhs ) \
323 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
326 template <class T, class B = ::boost::detail::empty_base<T> > \
329 friend T operator OP( const T& lhs, const T& rhs ) \
330 { T nrv( lhs ); nrv OP##= rhs; return nrv; } \
333 #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
335 #define BOOST_BINARY_OPERATOR( NAME, OP ) \
336 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
339 friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
342 template <class T, class B = ::boost::detail::empty_base<T> > \
345 friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
348 #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
350 BOOST_BINARY_OPERATOR( left_shiftable, << )
351 BOOST_BINARY_OPERATOR( right_shiftable, >> )
353 #undef BOOST_BINARY_OPERATOR
355 template <class T, class U, class B = ::boost::detail::empty_base<T> >
356 struct equivalent2 : B
358 friend bool operator==(const T& x, const U& y)
360 return !static_cast<bool>(x < y) && !static_cast<bool>(x > y);
364 template <class T, class B = ::boost::detail::empty_base<T> >
365 struct equivalent1 : B
367 friend bool operator==(const T&x, const T&y)
369 return !static_cast<bool>(x < y) && !static_cast<bool>(y < x);
373 template <class T, class U, class B = ::boost::detail::empty_base<T> >
374 struct partially_ordered2 : B
376 friend bool operator<=(const T& x, const U& y)
377 { return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
378 friend bool operator>=(const T& x, const U& y)
379 { return static_cast<bool>(x > y) || static_cast<bool>(x == y); }
380 friend bool operator>(const U& x, const T& y)
382 friend bool operator<(const U& x, const T& y)
384 friend bool operator<=(const U& x, const T& y)
385 { return static_cast<bool>(y > x) || static_cast<bool>(y == x); }
386 friend bool operator>=(const U& x, const T& y)
387 { return static_cast<bool>(y < x) || static_cast<bool>(y == x); }
390 template <class T, class B = ::boost::detail::empty_base<T> >
391 struct partially_ordered1 : B
393 friend bool operator>(const T& x, const T& y)
395 friend bool operator<=(const T& x, const T& y)
396 { return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
397 friend bool operator>=(const T& x, const T& y)
398 { return static_cast<bool>(y < x) || static_cast<bool>(x == y); }
401 // Combined operator classes (contributed by Daryle Walker) ----------------//
403 template <class T, class U, class B = ::boost::detail::empty_base<T> >
404 struct totally_ordered2
405 : less_than_comparable2<T, U
406 , equality_comparable2<T, U, B
409 template <class T, class B = ::boost::detail::empty_base<T> >
410 struct totally_ordered1
411 : less_than_comparable1<T
412 , equality_comparable1<T, B
415 template <class T, class U, class B = ::boost::detail::empty_base<T> >
418 , subtractable2<T, U, B
421 template <class T, class B = ::boost::detail::empty_base<T> >
427 template <class T, class U, class B = ::boost::detail::empty_base<T> >
428 struct multiplicative2
433 template <class T, class B = ::boost::detail::empty_base<T> >
434 struct multiplicative1
439 template <class T, class U, class B = ::boost::detail::empty_base<T> >
440 struct integer_multiplicative2
441 : multiplicative2<T, U
445 template <class T, class B = ::boost::detail::empty_base<T> >
446 struct integer_multiplicative1
451 template <class T, class U, class B = ::boost::detail::empty_base<T> >
454 , multiplicative2<T, U, B
457 template <class T, class B = ::boost::detail::empty_base<T> >
460 , multiplicative1<T, B
463 template <class T, class U, class B = ::boost::detail::empty_base<T> >
464 struct integer_arithmetic2
466 , integer_multiplicative2<T, U, B
469 template <class T, class B = ::boost::detail::empty_base<T> >
470 struct integer_arithmetic1
472 , integer_multiplicative1<T, B
475 template <class T, class U, class B = ::boost::detail::empty_base<T> >
482 template <class T, class B = ::boost::detail::empty_base<T> >
489 template <class T, class B = ::boost::detail::empty_base<T> >
490 struct unit_steppable
495 template <class T, class U, class B = ::boost::detail::empty_base<T> >
497 : left_shiftable2<T, U
498 , right_shiftable2<T, U, B
501 template <class T, class B = ::boost::detail::empty_base<T> >
504 , right_shiftable1<T, B
507 template <class T, class U, class B = ::boost::detail::empty_base<T> >
508 struct ring_operators2
510 , subtractable2_left<T, U
511 , multipliable2<T, U, B
514 template <class T, class B = ::boost::detail::empty_base<T> >
515 struct ring_operators1
520 template <class T, class U, class B = ::boost::detail::empty_base<T> >
521 struct ordered_ring_operators2
522 : ring_operators2<T, U
523 , totally_ordered2<T, U, B
526 template <class T, class B = ::boost::detail::empty_base<T> >
527 struct ordered_ring_operators1
529 , totally_ordered1<T, B
532 template <class T, class U, class B = ::boost::detail::empty_base<T> >
533 struct field_operators2
534 : ring_operators2<T, U
536 , dividable2_left<T, U, B
539 template <class T, class B = ::boost::detail::empty_base<T> >
540 struct field_operators1
545 template <class T, class U, class B = ::boost::detail::empty_base<T> >
546 struct ordered_field_operators2
547 : field_operators2<T, U
548 , totally_ordered2<T, U, B
551 template <class T, class B = ::boost::detail::empty_base<T> >
552 struct ordered_field_operators1
554 , totally_ordered1<T, B
557 template <class T, class U, class B = ::boost::detail::empty_base<T> >
558 struct euclidian_ring_operators2
559 : ring_operators2<T, U
561 , dividable2_left<T, U
563 , modable2_left<T, U, B
566 template <class T, class B = ::boost::detail::empty_base<T> >
567 struct euclidian_ring_operators1
573 template <class T, class U, class B = ::boost::detail::empty_base<T> >
574 struct ordered_euclidian_ring_operators2
575 : totally_ordered2<T, U
576 , euclidian_ring_operators2<T, U, B
579 template <class T, class B = ::boost::detail::empty_base<T> >
580 struct ordered_euclidian_ring_operators1
582 , euclidian_ring_operators1<T, B
585 template <class T, class U, class B = ::boost::detail::empty_base<T> >
586 struct euclidean_ring_operators2
587 : ring_operators2<T, U
589 , dividable2_left<T, U
591 , modable2_left<T, U, B
594 template <class T, class B = ::boost::detail::empty_base<T> >
595 struct euclidean_ring_operators1
601 template <class T, class U, class B = ::boost::detail::empty_base<T> >
602 struct ordered_euclidean_ring_operators2
603 : totally_ordered2<T, U
604 , euclidean_ring_operators2<T, U, B
607 template <class T, class B = ::boost::detail::empty_base<T> >
608 struct ordered_euclidean_ring_operators1
610 , euclidean_ring_operators1<T, B
613 template <class T, class P, class B = ::boost::detail::empty_base<T> >
614 struct input_iteratable
615 : equality_comparable1<T
617 , dereferenceable<T, P, B
620 template <class T, class B = ::boost::detail::empty_base<T> >
621 struct output_iteratable
625 template <class T, class P, class B = ::boost::detail::empty_base<T> >
626 struct forward_iteratable
627 : input_iteratable<T, P, B
630 template <class T, class P, class B = ::boost::detail::empty_base<T> >
631 struct bidirectional_iteratable
632 : forward_iteratable<T, P
636 // To avoid repeated derivation from equality_comparable,
637 // which is an indirect base class of bidirectional_iterable,
638 // random_access_iteratable must not be derived from totally_ordered1
639 // but from less_than_comparable1 only. (Helmut Zeisel, 02-Dec-2001)
640 template <class T, class P, class D, class R, class B = ::boost::detail::empty_base<T> >
641 struct random_access_iteratable
642 : bidirectional_iteratable<T, P
643 , less_than_comparable1<T
645 , indexable<T, D, R, B
648 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
650 #endif // BOOST_NO_OPERATORS_IN_NAMESPACE
653 // BOOST_IMPORT_TEMPLATE1 .. BOOST_IMPORT_TEMPLATE4 -
655 // When BOOST_NO_OPERATORS_IN_NAMESPACE is defined we need a way to import an
656 // operator template into the boost namespace. BOOST_IMPORT_TEMPLATE1 is used
657 // for one-argument forms of operator templates; BOOST_IMPORT_TEMPLATE2 for
658 // two-argument forms. Note that these macros expect to be invoked from within
661 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
663 // The template is already in boost so we have nothing to do.
664 # define BOOST_IMPORT_TEMPLATE4(template_name)
665 # define BOOST_IMPORT_TEMPLATE3(template_name)
666 # define BOOST_IMPORT_TEMPLATE2(template_name)
667 # define BOOST_IMPORT_TEMPLATE1(template_name)
669 #else // BOOST_NO_OPERATORS_IN_NAMESPACE
671 # ifndef BOOST_NO_USING_TEMPLATE
673 // Bring the names in with a using-declaration
674 // to avoid stressing the compiler.
675 # define BOOST_IMPORT_TEMPLATE4(template_name) using ::template_name;
676 # define BOOST_IMPORT_TEMPLATE3(template_name) using ::template_name;
677 # define BOOST_IMPORT_TEMPLATE2(template_name) using ::template_name;
678 # define BOOST_IMPORT_TEMPLATE1(template_name) using ::template_name;
682 // Otherwise, because a Borland C++ 5.5 bug prevents a using declaration
683 // from working, we are forced to use inheritance for that compiler.
684 # define BOOST_IMPORT_TEMPLATE4(template_name) \
685 template <class T, class U, class V, class W, class B = ::boost::detail::empty_base<T> > \
686 struct template_name : ::template_name<T, U, V, W, B> {};
688 # define BOOST_IMPORT_TEMPLATE3(template_name) \
689 template <class T, class U, class V, class B = ::boost::detail::empty_base<T> > \
690 struct template_name : ::template_name<T, U, V, B> {};
692 # define BOOST_IMPORT_TEMPLATE2(template_name) \
693 template <class T, class U, class B = ::boost::detail::empty_base<T> > \
694 struct template_name : ::template_name<T, U, B> {};
696 # define BOOST_IMPORT_TEMPLATE1(template_name) \
697 template <class T, class B = ::boost::detail::empty_base<T> > \
698 struct template_name : ::template_name<T, B> {};
700 # endif // BOOST_NO_USING_TEMPLATE
702 #endif // BOOST_NO_OPERATORS_IN_NAMESPACE
705 // Here's where we put it all together, defining the xxxx forms of the templates
706 // in namespace boost. We also define specializations of is_chained_base<> for
707 // the xxxx, xxxx1, and xxxx2 templates, importing them into boost:: as
711 // is_chained_base<> - a traits class used to distinguish whether an operator
712 // template argument is being used for base class chaining, or is specifying a
713 // 2nd argument type.
716 // A type parameter is used instead of a plain bool because Borland's compiler
717 // didn't cope well with the more obvious non-type template parameter.
721 } // namespace detail
723 // Unspecialized version assumes that most types are not being used for base
724 // class chaining. We specialize for the operator templates defined in this
726 template<class T> struct is_chained_base {
727 typedef ::boost::detail::false_t value;
732 // Import a 4-type-argument operator template into boost (if necessary) and
733 // provide a specialization of 'is_chained_base<>' for it.
734 # define BOOST_OPERATOR_TEMPLATE4(template_name4) \
735 BOOST_IMPORT_TEMPLATE4(template_name4) \
736 template<class T, class U, class V, class W, class B> \
737 struct is_chained_base< ::boost::template_name4<T, U, V, W, B> > { \
738 typedef ::boost::detail::true_t value; \
741 // Import a 3-type-argument operator template into boost (if necessary) and
742 // provide a specialization of 'is_chained_base<>' for it.
743 # define BOOST_OPERATOR_TEMPLATE3(template_name3) \
744 BOOST_IMPORT_TEMPLATE3(template_name3) \
745 template<class T, class U, class V, class B> \
746 struct is_chained_base< ::boost::template_name3<T, U, V, B> > { \
747 typedef ::boost::detail::true_t value; \
750 // Import a 2-type-argument operator template into boost (if necessary) and
751 // provide a specialization of 'is_chained_base<>' for it.
752 # define BOOST_OPERATOR_TEMPLATE2(template_name2) \
753 BOOST_IMPORT_TEMPLATE2(template_name2) \
754 template<class T, class U, class B> \
755 struct is_chained_base< ::boost::template_name2<T, U, B> > { \
756 typedef ::boost::detail::true_t value; \
759 // Import a 1-type-argument operator template into boost (if necessary) and
760 // provide a specialization of 'is_chained_base<>' for it.
761 # define BOOST_OPERATOR_TEMPLATE1(template_name1) \
762 BOOST_IMPORT_TEMPLATE1(template_name1) \
763 template<class T, class B> \
764 struct is_chained_base< ::boost::template_name1<T, B> > { \
765 typedef ::boost::detail::true_t value; \
768 // BOOST_OPERATOR_TEMPLATE(template_name) defines template_name<> such that it
769 // can be used for specifying both 1-argument and 2-argument forms. Requires the
770 // existence of two previously defined class templates named '<template_name>1'
771 // and '<template_name>2' which must implement the corresponding 1- and 2-
774 // The template type parameter O == is_chained_base<U>::value is used to
775 // distinguish whether the 2nd argument to <template_name> is being used for
776 // base class chaining from another boost operator template or is describing a
777 // 2nd operand type. O == true_t only when U is actually an another operator
778 // template from the library. Partial specialization is used to select an
779 // implementation in terms of either '<template_name>1' or '<template_name>2'.
782 # define BOOST_OPERATOR_TEMPLATE(template_name) \
785 ,class B = ::boost::detail::empty_base<T> \
786 ,class O = typename is_chained_base<U>::value \
788 struct template_name : template_name##2<T, U, B> {}; \
790 template<class T, class U, class B> \
791 struct template_name<T, U, B, ::boost::detail::true_t> \
792 : template_name##1<T, U> {}; \
794 template <class T, class B> \
795 struct template_name<T, T, B, ::boost::detail::false_t> \
796 : template_name##1<T, B> {}; \
798 template<class T, class U, class B, class O> \
799 struct is_chained_base< ::boost::template_name<T, U, B, O> > { \
800 typedef ::boost::detail::true_t value; \
803 BOOST_OPERATOR_TEMPLATE2(template_name##2) \
804 BOOST_OPERATOR_TEMPLATE1(template_name##1)
810 BOOST_OPERATOR_TEMPLATE(less_than_comparable)
811 BOOST_OPERATOR_TEMPLATE(equality_comparable)
812 BOOST_OPERATOR_TEMPLATE(multipliable)
813 BOOST_OPERATOR_TEMPLATE(addable)
814 BOOST_OPERATOR_TEMPLATE(subtractable)
815 BOOST_OPERATOR_TEMPLATE2(subtractable2_left)
816 BOOST_OPERATOR_TEMPLATE(dividable)
817 BOOST_OPERATOR_TEMPLATE2(dividable2_left)
818 BOOST_OPERATOR_TEMPLATE(modable)
819 BOOST_OPERATOR_TEMPLATE2(modable2_left)
820 BOOST_OPERATOR_TEMPLATE(xorable)
821 BOOST_OPERATOR_TEMPLATE(andable)
822 BOOST_OPERATOR_TEMPLATE(orable)
824 BOOST_OPERATOR_TEMPLATE1(incrementable)
825 BOOST_OPERATOR_TEMPLATE1(decrementable)
827 BOOST_OPERATOR_TEMPLATE2(dereferenceable)
828 BOOST_OPERATOR_TEMPLATE3(indexable)
830 BOOST_OPERATOR_TEMPLATE(left_shiftable)
831 BOOST_OPERATOR_TEMPLATE(right_shiftable)
832 BOOST_OPERATOR_TEMPLATE(equivalent)
833 BOOST_OPERATOR_TEMPLATE(partially_ordered)
835 BOOST_OPERATOR_TEMPLATE(totally_ordered)
836 BOOST_OPERATOR_TEMPLATE(additive)
837 BOOST_OPERATOR_TEMPLATE(multiplicative)
838 BOOST_OPERATOR_TEMPLATE(integer_multiplicative)
839 BOOST_OPERATOR_TEMPLATE(arithmetic)
840 BOOST_OPERATOR_TEMPLATE(integer_arithmetic)
841 BOOST_OPERATOR_TEMPLATE(bitwise)
842 BOOST_OPERATOR_TEMPLATE1(unit_steppable)
843 BOOST_OPERATOR_TEMPLATE(shiftable)
844 BOOST_OPERATOR_TEMPLATE(ring_operators)
845 BOOST_OPERATOR_TEMPLATE(ordered_ring_operators)
846 BOOST_OPERATOR_TEMPLATE(field_operators)
847 BOOST_OPERATOR_TEMPLATE(ordered_field_operators)
848 BOOST_OPERATOR_TEMPLATE(euclidian_ring_operators)
849 BOOST_OPERATOR_TEMPLATE(ordered_euclidian_ring_operators)
850 BOOST_OPERATOR_TEMPLATE(euclidean_ring_operators)
851 BOOST_OPERATOR_TEMPLATE(ordered_euclidean_ring_operators)
852 BOOST_OPERATOR_TEMPLATE2(input_iteratable)
853 BOOST_OPERATOR_TEMPLATE1(output_iteratable)
854 BOOST_OPERATOR_TEMPLATE2(forward_iteratable)
855 BOOST_OPERATOR_TEMPLATE2(bidirectional_iteratable)
856 BOOST_OPERATOR_TEMPLATE4(random_access_iteratable)
858 #undef BOOST_OPERATOR_TEMPLATE
859 #undef BOOST_OPERATOR_TEMPLATE4
860 #undef BOOST_OPERATOR_TEMPLATE3
861 #undef BOOST_OPERATOR_TEMPLATE2
862 #undef BOOST_OPERATOR_TEMPLATE1
863 #undef BOOST_IMPORT_TEMPLATE1
864 #undef BOOST_IMPORT_TEMPLATE2
865 #undef BOOST_IMPORT_TEMPLATE3
866 #undef BOOST_IMPORT_TEMPLATE4
868 // The following 'operators' classes can only be used portably if the derived class
869 // declares ALL of the required member operators.
870 template <class T, class U>
872 : totally_ordered2<T,U
873 , integer_arithmetic2<T,U
877 template <class T, class U = T>
878 struct operators : operators2<T, U> {};
880 template <class T> struct operators<T, T>
882 , integer_arithmetic<T
887 // Iterator helper classes (contributed by Jeremy Siek) -------------------//
888 // (Input and output iterator helpers contributed by Daryle Walker) -------//
889 // (Changed to use combined operator classes by Daryle Walker) ------------//
892 class D = std::ptrdiff_t,
895 struct input_iterator_helper
896 : input_iteratable<T, P
897 , std::iterator<std::input_iterator_tag, V, D, P, R
901 struct output_iterator_helper
902 : output_iteratable<T
903 , std::iterator<std::output_iterator_tag, void, void, void, void
906 T& operator*() { return static_cast<T&>(*this); }
907 T& operator++() { return static_cast<T&>(*this); }
912 class D = std::ptrdiff_t,
915 struct forward_iterator_helper
916 : forward_iteratable<T, P
917 , std::iterator<std::forward_iterator_tag, V, D, P, R
922 class D = std::ptrdiff_t,
925 struct bidirectional_iterator_helper
926 : bidirectional_iteratable<T, P
927 , std::iterator<std::bidirectional_iterator_tag, V, D, P, R
932 class D = std::ptrdiff_t,
935 struct random_access_iterator_helper
936 : random_access_iteratable<T, P, D, R
937 , std::iterator<std::random_access_iterator_tag, V, D, P, R
940 friend D requires_difference_operator(const T& x, const T& y) {
943 }; // random_access_iterator_helper
947 #if defined(__sgi) && !defined(__GNUC__)
948 #pragma reset woff 1234
951 #endif // BOOST_OPERATORS_V1_HPP