BVB Source Codes

mars Show operators.hpp Source code

Return Download mars: download operators.hpp Source code - Download mars Source code - Type:.hpp
  1. //  Boost operators.hpp header file  ----------------------------------------//
  2.  
  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)
  7.  
  8. //  See http://www.boost.org/libs/utility/operators.htm for documentation.
  9.  
  10. //  Revision History
  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
  41. //            Dave Abrahams)
  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
  45. //            (Mark Rodgers)
  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
  49. //            for the details.
  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
  61.  
  62. // 10 Jun 00:
  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.
  71. //
  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.
  77. //
  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.
  81.  
  82. #ifndef BOOST_OPERATORS_HPP
  83. #define BOOST_OPERATORS_HPP
  84.  
  85. #include <cstddef>
  86. #include <iterator>
  87.  
  88. #include <boost/config.hpp>
  89. #include <boost/detail/workaround.hpp>
  90.  
  91. #if defined(__sgi) && !defined(__GNUC__)
  92. #   pragma set woff 1234
  93. #endif
  94.  
  95. #if BOOST_WORKAROUND(BOOST_MSVC, < 1600)
  96. #   pragma warning( disable : 4284 ) // complaint about return type of
  97. #endif                               // operator-> not begin a UDT
  98.  
  99. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  100. namespace detail {
  101.  
  102. template <typename T> class empty_base {};
  103.  
  104. } // namespace detail
  105. } // namespace mars_boost
  106.  
  107. // In this section we supply the xxxx1 and xxxx2 forms of the operator
  108. // templates, which are explicitly targeted at the 1-type-argument and
  109. // 2-type-argument operator forms, respectively. Some compilers get confused
  110. // when inline friend functions are overloaded in namespaces other than the
  111. // global namespace. When BOOST_NO_OPERATORS_IN_NAMESPACE is defined, all of
  112. // these templates must go in the global namespace.
  113.  
  114. #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
  115. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost
  116. {
  117. #endif
  118.  
  119. //  Basic operator classes (contributed by Dave Abrahams) ------------------//
  120.  
  121. //  Note that friend functions defined in a class are implicitly inline.
  122. //  See the C++ std, 11.4 [class.friend] paragraph 5
  123.  
  124. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  125. struct less_than_comparable2 : B
  126. {
  127.      friend bool operator<=(const T& x, const U& y) { return !static_cast<bool>(x > y); }
  128.      friend bool operator>=(const T& x, const U& y) { return !static_cast<bool>(x < y); }
  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 !static_cast<bool>(y < x); }
  132.      friend bool operator>=(const U& x, const T& y) { return !static_cast<bool>(y > x); }
  133. };
  134.  
  135. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  136. struct less_than_comparable1 : B
  137. {
  138.      friend bool operator>(const T& x, const T& y)  { return y < x; }
  139.      friend bool operator<=(const T& x, const T& y) { return !static_cast<bool>(y < x); }
  140.      friend bool operator>=(const T& x, const T& y) { return !static_cast<bool>(x < y); }
  141. };
  142.  
  143. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  144. struct equality_comparable2 : B
  145. {
  146.      friend bool operator==(const U& y, const T& x) { return x == y; }
  147.      friend bool operator!=(const U& y, const T& x) { return !static_cast<bool>(x == y); }
  148.      friend bool operator!=(const T& y, const U& x) { return !static_cast<bool>(y == x); }
  149. };
  150.  
  151. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  152. struct equality_comparable1 : B
  153. {
  154.      friend bool operator!=(const T& x, const T& y) { return !static_cast<bool>(x == y); }
  155. };
  156.  
  157. // A macro which produces "name_2left" from "name".
  158. #define BOOST_OPERATOR2_LEFT(name) name##2##_##left
  159.  
  160. //  NRVO-friendly implementation (contributed by Daniel Frey) ---------------//
  161.  
  162. #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
  163.  
  164. // This is the optimal implementation for ISO/ANSI C++,
  165. // but it requires the compiler to implement the NRVO.
  166. // If the compiler has no NRVO, this is the best symmetric
  167. // implementation available.
  168.  
  169. #define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP )                         \
  170. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >        \
  171. struct NAME##2 : B                                                            \
  172. {                                                                             \
  173.   friend T operator OP( const T& lhs, const U& rhs )                          \
  174.     { T nrv( lhs ); nrv OP##= rhs; return nrv; }                              \
  175.   friend T operator OP( const U& lhs, const T& rhs )                          \
  176.     { T nrv( rhs ); nrv OP##= lhs; return nrv; }                              \
  177. };                                                                            \
  178.                                                                               \
  179. template <class T, class B = ::mars_boost::detail::empty_base<T> >                 \
  180. struct NAME##1 : B                                                            \
  181. {                                                                             \
  182.   friend T operator OP( const T& lhs, const T& rhs )                          \
  183.     { T nrv( lhs ); nrv OP##= rhs; return nrv; }                              \
  184. };
  185.  
  186. #define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP )               \
  187. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >  \
  188. struct NAME##2 : B                                                      \
  189. {                                                                       \
  190.   friend T operator OP( const T& lhs, const U& rhs )                    \
  191.     { T nrv( lhs ); nrv OP##= rhs; return nrv; }                        \
  192. };                                                                      \
  193.                                                                         \
  194. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >  \
  195. struct BOOST_OPERATOR2_LEFT(NAME) : B                                   \
  196. {                                                                       \
  197.   friend T operator OP( const U& lhs, const T& rhs )                    \
  198.     { T nrv( lhs ); nrv OP##= rhs; return nrv; }                        \
  199. };                                                                      \
  200.                                                                         \
  201. template <class T, class B = ::mars_boost::detail::empty_base<T> >           \
  202. struct NAME##1 : B                                                      \
  203. {                                                                       \
  204.   friend T operator OP( const T& lhs, const T& rhs )                    \
  205.     { T nrv( lhs ); nrv OP##= rhs; return nrv; }                        \
  206. };
  207.  
  208. #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
  209.  
  210. // For compilers without NRVO the following code is optimal, but not
  211. // symmetric!  Note that the implementation of
  212. // BOOST_OPERATOR2_LEFT(NAME) only looks cool, but doesn't provide
  213. // optimization opportunities to the compiler :)
  214.  
  215. #define BOOST_BINARY_OPERATOR_COMMUTATIVE( NAME, OP )                   \
  216. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >  \
  217. struct NAME##2 : B                                                      \
  218. {                                                                       \
  219.   friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
  220.   friend T operator OP( const U& lhs, T rhs ) { return rhs OP##= lhs; } \
  221. };                                                                      \
  222.                                                                         \
  223. template <class T, class B = ::mars_boost::detail::empty_base<T> >           \
  224. struct NAME##1 : B                                                      \
  225. {                                                                       \
  226.   friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
  227. };
  228.  
  229. #define BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( NAME, OP )               \
  230. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >  \
  231. struct NAME##2 : B                                                      \
  232. {                                                                       \
  233.   friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; } \
  234. };                                                                      \
  235.                                                                         \
  236. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >  \
  237. struct BOOST_OPERATOR2_LEFT(NAME) : B                                   \
  238. {                                                                       \
  239.   friend T operator OP( const U& lhs, const T& rhs )                    \
  240.     { return T( lhs ) OP##= rhs; }                                      \
  241. };                                                                      \
  242.                                                                         \
  243. template <class T, class B = ::mars_boost::detail::empty_base<T> >           \
  244. struct NAME##1 : B                                                      \
  245. {                                                                       \
  246.   friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; } \
  247. };
  248.  
  249. #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
  250.  
  251. BOOST_BINARY_OPERATOR_COMMUTATIVE( multipliable, * )
  252. BOOST_BINARY_OPERATOR_COMMUTATIVE( addable, + )
  253. BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( subtractable, - )
  254. BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( dividable, / )
  255. BOOST_BINARY_OPERATOR_NON_COMMUTATIVE( modable, % )
  256. BOOST_BINARY_OPERATOR_COMMUTATIVE( xorable, ^ )
  257. BOOST_BINARY_OPERATOR_COMMUTATIVE( andable, & )
  258. BOOST_BINARY_OPERATOR_COMMUTATIVE( orable, | )
  259.  
  260. #undef BOOST_BINARY_OPERATOR_COMMUTATIVE
  261. #undef BOOST_BINARY_OPERATOR_NON_COMMUTATIVE
  262. #undef BOOST_OPERATOR2_LEFT
  263.  
  264. //  incrementable and decrementable contributed by Jeremy Siek
  265.  
  266. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  267. struct incrementable : B
  268. {
  269.   friend T operator++(T& x, int)
  270.   {
  271.     incrementable_type nrv(x);
  272.     ++x;
  273.     return nrv;
  274.   }
  275. private: // The use of this typedef works around a Borland bug
  276.   typedef T incrementable_type;
  277. };
  278.  
  279. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  280. struct decrementable : B
  281. {
  282.   friend T operator--(T& x, int)
  283.   {
  284.     decrementable_type nrv(x);
  285.     --x;
  286.     return nrv;
  287.   }
  288. private: // The use of this typedef works around a Borland bug
  289.   typedef T decrementable_type;
  290. };
  291.  
  292. //  Iterator operator classes (contributed by Jeremy Siek) ------------------//
  293.  
  294. template <class T, class P, class B = ::mars_boost::detail::empty_base<T> >
  295. struct dereferenceable : B
  296. {
  297.   P operator->() const
  298.   {
  299.     return &*static_cast<const T&>(*this);
  300.   }
  301. };
  302.  
  303. template <class T, class I, class R, class B = ::mars_boost::detail::empty_base<T> >
  304. struct indexable : B
  305. {
  306.   R operator[](I n) const
  307.   {
  308.     return *(static_cast<const T&>(*this) + n);
  309.   }
  310. };
  311.  
  312. //  More operator classes (contributed by Daryle Walker) --------------------//
  313. //  (NRVO-friendly implementation contributed by Daniel Frey) ---------------//
  314.  
  315. #if defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
  316.  
  317. #define BOOST_BINARY_OPERATOR( NAME, OP )                                     \
  318. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >        \
  319. struct NAME##2 : B                                                            \
  320. {                                                                             \
  321.   friend T operator OP( const T& lhs, const U& rhs )                          \
  322.     { T nrv( lhs ); nrv OP##= rhs; return nrv; }                              \
  323. };                                                                            \
  324.                                                                               \
  325. template <class T, class B = ::mars_boost::detail::empty_base<T> >                 \
  326. struct NAME##1 : B                                                            \
  327. {                                                                             \
  328.   friend T operator OP( const T& lhs, const T& rhs )                          \
  329.     { T nrv( lhs ); nrv OP##= rhs; return nrv; }                              \
  330. };
  331.  
  332. #else // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
  333.  
  334. #define BOOST_BINARY_OPERATOR( NAME, OP )                                     \
  335. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >        \
  336. struct NAME##2 : B                                                            \
  337. {                                                                             \
  338.   friend T operator OP( T lhs, const U& rhs ) { return lhs OP##= rhs; }       \
  339. };                                                                            \
  340.                                                                               \
  341. template <class T, class B = ::mars_boost::detail::empty_base<T> >                 \
  342. struct NAME##1 : B                                                            \
  343. {                                                                             \
  344.   friend T operator OP( T lhs, const T& rhs ) { return lhs OP##= rhs; }       \
  345. };
  346.  
  347. #endif // defined(BOOST_HAS_NRVO) || defined(BOOST_FORCE_SYMMETRIC_OPERATORS)
  348.  
  349. BOOST_BINARY_OPERATOR( left_shiftable, << )
  350. BOOST_BINARY_OPERATOR( right_shiftable, >> )
  351.  
  352. #undef BOOST_BINARY_OPERATOR
  353.  
  354. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  355. struct equivalent2 : B
  356. {
  357.   friend bool operator==(const T& x, const U& y)
  358.   {
  359.     return !static_cast<bool>(x < y) && !static_cast<bool>(x > y);
  360.   }
  361. };
  362.  
  363. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  364. struct equivalent1 : B
  365. {
  366.   friend bool operator==(const T&x, const T&y)
  367.   {
  368.     return !static_cast<bool>(x < y) && !static_cast<bool>(y < x);
  369.   }
  370. };
  371.  
  372. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  373. struct partially_ordered2 : B
  374. {
  375.   friend bool operator<=(const T& x, const U& y)
  376.     { return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
  377.   friend bool operator>=(const T& x, const U& y)
  378.     { return static_cast<bool>(x > y) || static_cast<bool>(x == y); }
  379.   friend bool operator>(const U& x, const T& y)
  380.     { return y < x; }
  381.   friend bool operator<(const U& x, const T& y)
  382.     { return y > x; }
  383.   friend bool operator<=(const U& x, const T& y)
  384.     { return static_cast<bool>(y > x) || static_cast<bool>(y == x); }
  385.   friend bool operator>=(const U& x, const T& y)
  386.     { return static_cast<bool>(y < x) || static_cast<bool>(y == x); }
  387. };
  388.  
  389. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  390. struct partially_ordered1 : B
  391. {
  392.   friend bool operator>(const T& x, const T& y)
  393.     { return y < x; }
  394.   friend bool operator<=(const T& x, const T& y)
  395.     { return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
  396.   friend bool operator>=(const T& x, const T& y)
  397.     { return static_cast<bool>(y < x) || static_cast<bool>(x == y); }
  398. };
  399.  
  400. //  Combined operator classes (contributed by Daryle Walker) ----------------//
  401.  
  402. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  403. struct totally_ordered2
  404.     : less_than_comparable2<T, U
  405.     , equality_comparable2<T, U, B
  406.       > > {};
  407.  
  408. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  409. struct totally_ordered1
  410.     : less_than_comparable1<T
  411.     , equality_comparable1<T, B
  412.       > > {};
  413.  
  414. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  415. struct additive2
  416.     : addable2<T, U
  417.     , subtractable2<T, U, B
  418.       > > {};
  419.  
  420. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  421. struct additive1
  422.     : addable1<T
  423.     , subtractable1<T, B
  424.       > > {};
  425.  
  426. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  427. struct multiplicative2
  428.     : multipliable2<T, U
  429.     , dividable2<T, U, B
  430.       > > {};
  431.  
  432. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  433. struct multiplicative1
  434.     : multipliable1<T
  435.     , dividable1<T, B
  436.       > > {};
  437.  
  438. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  439. struct integer_multiplicative2
  440.     : multiplicative2<T, U
  441.     , modable2<T, U, B
  442.       > > {};
  443.  
  444. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  445. struct integer_multiplicative1
  446.     : multiplicative1<T
  447.     , modable1<T, B
  448.       > > {};
  449.  
  450. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  451. struct arithmetic2
  452.     : additive2<T, U
  453.     , multiplicative2<T, U, B
  454.       > > {};
  455.  
  456. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  457. struct arithmetic1
  458.     : additive1<T
  459.     , multiplicative1<T, B
  460.       > > {};
  461.  
  462. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  463. struct integer_arithmetic2
  464.     : additive2<T, U
  465.     , integer_multiplicative2<T, U, B
  466.       > > {};
  467.  
  468. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  469. struct integer_arithmetic1
  470.     : additive1<T
  471.     , integer_multiplicative1<T, B
  472.       > > {};
  473.  
  474. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  475. struct bitwise2
  476.     : xorable2<T, U
  477.     , andable2<T, U
  478.     , orable2<T, U, B
  479.       > > > {};
  480.  
  481. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  482. struct bitwise1
  483.     : xorable1<T
  484.     , andable1<T
  485.     , orable1<T, B
  486.       > > > {};
  487.  
  488. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  489. struct unit_steppable
  490.     : incrementable<T
  491.     , decrementable<T, B
  492.       > > {};
  493.  
  494. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  495. struct shiftable2
  496.     : left_shiftable2<T, U
  497.     , right_shiftable2<T, U, B
  498.       > > {};
  499.  
  500. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  501. struct shiftable1
  502.     : left_shiftable1<T
  503.     , right_shiftable1<T, B
  504.       > > {};
  505.  
  506. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  507. struct ring_operators2
  508.     : additive2<T, U
  509.     , subtractable2_left<T, U
  510.     , multipliable2<T, U, B
  511.       > > > {};
  512.  
  513. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  514. struct ring_operators1
  515.     : additive1<T
  516.     , multipliable1<T, B
  517.       > > {};
  518.  
  519. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  520. struct ordered_ring_operators2
  521.     : ring_operators2<T, U
  522.     , totally_ordered2<T, U, B
  523.       > > {};
  524.  
  525. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  526. struct ordered_ring_operators1
  527.     : ring_operators1<T
  528.     , totally_ordered1<T, B
  529.       > > {};
  530.  
  531. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  532. struct field_operators2
  533.     : ring_operators2<T, U
  534.     , dividable2<T, U
  535.     , dividable2_left<T, U, B
  536.       > > > {};
  537.  
  538. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  539. struct field_operators1
  540.     : ring_operators1<T
  541.     , dividable1<T, B
  542.       > > {};
  543.  
  544. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  545. struct ordered_field_operators2
  546.     : field_operators2<T, U
  547.     , totally_ordered2<T, U, B
  548.       > > {};
  549.  
  550. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  551. struct ordered_field_operators1
  552.     : field_operators1<T
  553.     , totally_ordered1<T, B
  554.       > > {};
  555.  
  556. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  557. struct euclidian_ring_operators2
  558.     : ring_operators2<T, U
  559.     , dividable2<T, U
  560.     , dividable2_left<T, U
  561.     , modable2<T, U
  562.     , modable2_left<T, U, B
  563.       > > > > > {};
  564.  
  565. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  566. struct euclidian_ring_operators1
  567.     : ring_operators1<T
  568.     , dividable1<T
  569.     , modable1<T, B
  570.       > > > {};
  571.  
  572. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  573. struct ordered_euclidian_ring_operators2
  574.     : totally_ordered2<T, U
  575.     , euclidian_ring_operators2<T, U, B
  576.       > > {};
  577.  
  578. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  579. struct ordered_euclidian_ring_operators1
  580.     : totally_ordered1<T
  581.     , euclidian_ring_operators1<T, B
  582.       > > {};
  583.  
  584. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  585. struct euclidean_ring_operators2
  586.     : ring_operators2<T, U
  587.     , dividable2<T, U
  588.     , dividable2_left<T, U
  589.     , modable2<T, U
  590.     , modable2_left<T, U, B
  591.       > > > > > {};
  592.  
  593. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  594. struct euclidean_ring_operators1
  595.     : ring_operators1<T
  596.     , dividable1<T
  597.     , modable1<T, B
  598.       > > > {};
  599.  
  600. template <class T, class U, class B = ::mars_boost::detail::empty_base<T> >
  601. struct ordered_euclidean_ring_operators2
  602.     : totally_ordered2<T, U
  603.     , euclidean_ring_operators2<T, U, B
  604.       > > {};
  605.  
  606. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  607. struct ordered_euclidean_ring_operators1
  608.     : totally_ordered1<T
  609.     , euclidean_ring_operators1<T, B
  610.       > > {};
  611.  
  612. template <class T, class P, class B = ::mars_boost::detail::empty_base<T> >
  613. struct input_iteratable
  614.     : equality_comparable1<T
  615.     , incrementable<T
  616.     , dereferenceable<T, P, B
  617.       > > > {};
  618.  
  619. template <class T, class B = ::mars_boost::detail::empty_base<T> >
  620. struct output_iteratable
  621.     : incrementable<T, B
  622.       > {};
  623.  
  624. template <class T, class P, class B = ::mars_boost::detail::empty_base<T> >
  625. struct forward_iteratable
  626.     : input_iteratable<T, P, B
  627.       > {};
  628.  
  629. template <class T, class P, class B = ::mars_boost::detail::empty_base<T> >
  630. struct bidirectional_iteratable
  631.     : forward_iteratable<T, P
  632.     , decrementable<T, B
  633.       > > {};
  634.  
  635. //  To avoid repeated derivation from equality_comparable,
  636. //  which is an indirect base class of bidirectional_iterable,
  637. //  random_access_iteratable must not be derived from totally_ordered1
  638. //  but from less_than_comparable1 only. (Helmut Zeisel, 02-Dec-2001)
  639. template <class T, class P, class D, class R, class B = ::mars_boost::detail::empty_base<T> >
  640. struct random_access_iteratable
  641.     : bidirectional_iteratable<T, P
  642.     , less_than_comparable1<T
  643.     , additive2<T, D
  644.     , indexable<T, D, R, B
  645.       > > > > {};
  646.  
  647. #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
  648. } // namespace mars_boost
  649. #endif // BOOST_NO_OPERATORS_IN_NAMESPACE
  650.  
  651.  
  652. // BOOST_IMPORT_TEMPLATE1 .. BOOST_IMPORT_TEMPLATE4 -
  653. //
  654. // When BOOST_NO_OPERATORS_IN_NAMESPACE is defined we need a way to import an
  655. // operator template into the boost namespace. BOOST_IMPORT_TEMPLATE1 is used
  656. // for one-argument forms of operator templates; BOOST_IMPORT_TEMPLATE2 for
  657. // two-argument forms. Note that these macros expect to be invoked from within
  658. // boost.
  659.  
  660. #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
  661.  
  662.   // The template is already in boost so we have nothing to do.
  663. # define BOOST_IMPORT_TEMPLATE4(template_name)
  664. # define BOOST_IMPORT_TEMPLATE3(template_name)
  665. # define BOOST_IMPORT_TEMPLATE2(template_name)
  666. # define BOOST_IMPORT_TEMPLATE1(template_name)
  667.  
  668. #else // BOOST_NO_OPERATORS_IN_NAMESPACE
  669.  
  670. #  ifndef BOOST_NO_USING_TEMPLATE
  671.  
  672.      // Bring the names in with a using-declaration
  673.      // to avoid stressing the compiler.
  674. #    define BOOST_IMPORT_TEMPLATE4(template_name) using ::template_name;
  675. #    define BOOST_IMPORT_TEMPLATE3(template_name) using ::template_name;
  676. #    define BOOST_IMPORT_TEMPLATE2(template_name) using ::template_name;
  677. #    define BOOST_IMPORT_TEMPLATE1(template_name) using ::template_name;
  678.  
  679. #  else
  680.  
  681.      // Otherwise, because a Borland C++ 5.5 bug prevents a using declaration
  682.      // from working, we are forced to use inheritance for that compiler.
  683. #    define BOOST_IMPORT_TEMPLATE4(template_name)                                             \
  684.      template <class T, class U, class V, class W, class B = ::mars_boost::detail::empty_base<T> > \
  685.      struct template_name : ::template_name<T, U, V, W, B> {};
  686.  
  687. #    define BOOST_IMPORT_TEMPLATE3(template_name)                                    \
  688.      template <class T, class U, class V, class B = ::mars_boost::detail::empty_base<T> > \
  689.      struct template_name : ::template_name<T, U, V, B> {};
  690.  
  691. #    define BOOST_IMPORT_TEMPLATE2(template_name)                           \
  692.      template <class T, class U, class B = ::mars_boost::detail::empty_base<T> > \
  693.      struct template_name : ::template_name<T, U, B> {};
  694.  
  695. #    define BOOST_IMPORT_TEMPLATE1(template_name)                  \
  696.      template <class T, class B = ::mars_boost::detail::empty_base<T> > \
  697.      struct template_name : ::template_name<T, B> {};
  698.  
  699. #  endif // BOOST_NO_USING_TEMPLATE
  700.  
  701. #endif // BOOST_NO_OPERATORS_IN_NAMESPACE
  702.  
  703. //
  704. // Here's where we put it all together, defining the xxxx forms of the templates
  705. // in namespace mars_boost. We also define specializations of is_chained_base<> for
  706. // the xxxx, xxxx1, and xxxx2 templates, importing them into mars_boost:: as
  707. // necessary.
  708. //
  709.  
  710. // is_chained_base<> - a traits class used to distinguish whether an operator
  711. // template argument is being used for base class chaining, or is specifying a
  712. // 2nd argument type.
  713.  
  714. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  715. // A type parameter is used instead of a plain bool because Borland's compiler
  716. // didn't cope well with the more obvious non-type template parameter.
  717. namespace detail {
  718.   struct true_t {};
  719.   struct false_t {};
  720. } // namespace detail
  721.  
  722. // Unspecialized version assumes that most types are not being used for base
  723. // class chaining. We specialize for the operator templates defined in this
  724. // library.
  725. template<class T> struct is_chained_base {
  726.   typedef ::mars_boost::detail::false_t value;
  727. };
  728.  
  729. } // namespace mars_boost
  730.  
  731. // Import a 4-type-argument operator template into boost (if necessary) and
  732. // provide a specialization of 'is_chained_base<>' for it.
  733. # define BOOST_OPERATOR_TEMPLATE4(template_name4)                     \
  734.   BOOST_IMPORT_TEMPLATE4(template_name4)                              \
  735.   template<class T, class U, class V, class W, class B>               \
  736.   struct is_chained_base< ::mars_boost::template_name4<T, U, V, W, B> > {  \
  737.     typedef ::mars_boost::detail::true_t value;                            \
  738.   };
  739.  
  740. // Import a 3-type-argument operator template into boost (if necessary) and
  741. // provide a specialization of 'is_chained_base<>' for it.
  742. # define BOOST_OPERATOR_TEMPLATE3(template_name3)                     \
  743.   BOOST_IMPORT_TEMPLATE3(template_name3)                              \
  744.   template<class T, class U, class V, class B>                        \
  745.   struct is_chained_base< ::mars_boost::template_name3<T, U, V, B> > {     \
  746.     typedef ::mars_boost::detail::true_t value;                            \
  747.   };
  748.  
  749. // Import a 2-type-argument operator template into boost (if necessary) and
  750. // provide a specialization of 'is_chained_base<>' for it.
  751. # define BOOST_OPERATOR_TEMPLATE2(template_name2)                  \
  752.   BOOST_IMPORT_TEMPLATE2(template_name2)                           \
  753.   template<class T, class U, class B>                              \
  754.   struct is_chained_base< ::mars_boost::template_name2<T, U, B> > {     \
  755.     typedef ::mars_boost::detail::true_t value;                         \
  756.   };
  757.  
  758. // Import a 1-type-argument operator template into boost (if necessary) and
  759. // provide a specialization of 'is_chained_base<>' for it.
  760. # define BOOST_OPERATOR_TEMPLATE1(template_name1)                  \
  761.   BOOST_IMPORT_TEMPLATE1(template_name1)                           \
  762.   template<class T, class B>                                       \
  763.   struct is_chained_base< ::mars_boost::template_name1<T, B> > {        \
  764.     typedef ::mars_boost::detail::true_t value;                         \
  765.   };
  766.  
  767. // BOOST_OPERATOR_TEMPLATE(template_name) defines template_name<> such that it
  768. // can be used for specifying both 1-argument and 2-argument forms. Requires the
  769. // existence of two previously defined class templates named '<template_name>1'
  770. // and '<template_name>2' which must implement the corresponding 1- and 2-
  771. // argument forms.
  772. //
  773. // The template type parameter O == is_chained_base<U>::value is used to
  774. // distinguish whether the 2nd argument to <template_name> is being used for
  775. // base class chaining from another boost operator template or is describing a
  776. // 2nd operand type. O == true_t only when U is actually an another operator
  777. // template from the library. Partial specialization is used to select an
  778. // implementation in terms of either '<template_name>1' or '<template_name>2'.
  779. //
  780.  
  781. # define BOOST_OPERATOR_TEMPLATE(template_name)                    \
  782. template <class T                                                  \
  783.          ,class U = T                                              \
  784.          ,class B = ::mars_boost::detail::empty_base<T>                 \
  785.          ,class O = typename is_chained_base<U>::value             \
  786.          >                                                         \
  787. struct template_name : template_name##2<T, U, B> {};               \
  788.                                                                    \
  789. template<class T, class U, class B>                                \
  790. struct template_name<T, U, B, ::mars_boost::detail::true_t>             \
  791.   : template_name##1<T, U> {};                                     \
  792.                                                                    \
  793. template <class T, class B>                                        \
  794. struct template_name<T, T, B, ::mars_boost::detail::false_t>            \
  795.   : template_name##1<T, B> {};                                     \
  796.                                                                    \
  797. template<class T, class U, class B, class O>                       \
  798. struct is_chained_base< ::mars_boost::template_name<T, U, B, O> > {     \
  799.   typedef ::mars_boost::detail::true_t value;                           \
  800. };                                                                 \
  801.                                                                    \
  802. BOOST_OPERATOR_TEMPLATE2(template_name##2)                         \
  803. BOOST_OPERATOR_TEMPLATE1(template_name##1)
  804.  
  805.  
  806.  
  807. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  808.    
  809. BOOST_OPERATOR_TEMPLATE(less_than_comparable)
  810. BOOST_OPERATOR_TEMPLATE(equality_comparable)
  811. BOOST_OPERATOR_TEMPLATE(multipliable)
  812. BOOST_OPERATOR_TEMPLATE(addable)
  813. BOOST_OPERATOR_TEMPLATE(subtractable)
  814. BOOST_OPERATOR_TEMPLATE2(subtractable2_left)
  815. BOOST_OPERATOR_TEMPLATE(dividable)
  816. BOOST_OPERATOR_TEMPLATE2(dividable2_left)
  817. BOOST_OPERATOR_TEMPLATE(modable)
  818. BOOST_OPERATOR_TEMPLATE2(modable2_left)
  819. BOOST_OPERATOR_TEMPLATE(xorable)
  820. BOOST_OPERATOR_TEMPLATE(andable)
  821. BOOST_OPERATOR_TEMPLATE(orable)
  822.  
  823. BOOST_OPERATOR_TEMPLATE1(incrementable)
  824. BOOST_OPERATOR_TEMPLATE1(decrementable)
  825.  
  826. BOOST_OPERATOR_TEMPLATE2(dereferenceable)
  827. BOOST_OPERATOR_TEMPLATE3(indexable)
  828.  
  829. BOOST_OPERATOR_TEMPLATE(left_shiftable)
  830. BOOST_OPERATOR_TEMPLATE(right_shiftable)
  831. BOOST_OPERATOR_TEMPLATE(equivalent)
  832. BOOST_OPERATOR_TEMPLATE(partially_ordered)
  833.  
  834. BOOST_OPERATOR_TEMPLATE(totally_ordered)
  835. BOOST_OPERATOR_TEMPLATE(additive)
  836. BOOST_OPERATOR_TEMPLATE(multiplicative)
  837. BOOST_OPERATOR_TEMPLATE(integer_multiplicative)
  838. BOOST_OPERATOR_TEMPLATE(arithmetic)
  839. BOOST_OPERATOR_TEMPLATE(integer_arithmetic)
  840. BOOST_OPERATOR_TEMPLATE(bitwise)
  841. BOOST_OPERATOR_TEMPLATE1(unit_steppable)
  842. BOOST_OPERATOR_TEMPLATE(shiftable)
  843. BOOST_OPERATOR_TEMPLATE(ring_operators)
  844. BOOST_OPERATOR_TEMPLATE(ordered_ring_operators)
  845. BOOST_OPERATOR_TEMPLATE(field_operators)
  846. BOOST_OPERATOR_TEMPLATE(ordered_field_operators)
  847. BOOST_OPERATOR_TEMPLATE(euclidian_ring_operators)
  848. BOOST_OPERATOR_TEMPLATE(ordered_euclidian_ring_operators)
  849. BOOST_OPERATOR_TEMPLATE(euclidean_ring_operators)
  850. BOOST_OPERATOR_TEMPLATE(ordered_euclidean_ring_operators)
  851. BOOST_OPERATOR_TEMPLATE2(input_iteratable)
  852. BOOST_OPERATOR_TEMPLATE1(output_iteratable)
  853. BOOST_OPERATOR_TEMPLATE2(forward_iteratable)
  854. BOOST_OPERATOR_TEMPLATE2(bidirectional_iteratable)
  855. BOOST_OPERATOR_TEMPLATE4(random_access_iteratable)
  856.  
  857. #undef BOOST_OPERATOR_TEMPLATE
  858. #undef BOOST_OPERATOR_TEMPLATE4
  859. #undef BOOST_OPERATOR_TEMPLATE3
  860. #undef BOOST_OPERATOR_TEMPLATE2
  861. #undef BOOST_OPERATOR_TEMPLATE1
  862. #undef BOOST_IMPORT_TEMPLATE1
  863. #undef BOOST_IMPORT_TEMPLATE2
  864. #undef BOOST_IMPORT_TEMPLATE3
  865. #undef BOOST_IMPORT_TEMPLATE4
  866.  
  867. // The following 'operators' classes can only be used portably if the derived class
  868. // declares ALL of the required member operators.
  869. template <class T, class U>
  870. struct operators2
  871.     : totally_ordered2<T,U
  872.     , integer_arithmetic2<T,U
  873.     , bitwise2<T,U
  874.       > > > {};
  875.  
  876. template <class T, class U = T>
  877. struct operators : operators2<T, U> {};
  878.  
  879. template <class T> struct operators<T, T>
  880.     : totally_ordered<T
  881.     , integer_arithmetic<T
  882.     , bitwise<T
  883.     , unit_steppable<T
  884.       > > > > {};
  885.  
  886. //  Iterator helper classes (contributed by Jeremy Siek) -------------------//
  887. //  (Input and output iterator helpers contributed by Daryle Walker) -------//
  888. //  (Changed to use combined operator classes by Daryle Walker) ------------//
  889. template <class T,
  890.           class V,
  891.           class D = std::ptrdiff_t,
  892.           class P = V const *,
  893.           class R = V const &>
  894. struct input_iterator_helper
  895.   : input_iteratable<T, P
  896.   , std::iterator<std::input_iterator_tag, V, D, P, R
  897.     > > {};
  898.  
  899. template<class T>
  900. struct output_iterator_helper
  901.   : output_iteratable<T
  902.   , std::iterator<std::output_iterator_tag, void, void, void, void
  903.   > >
  904. {
  905.   T& operator*()  { return static_cast<T&>(*this); }
  906.   T& operator++() { return static_cast<T&>(*this); }
  907. };
  908.  
  909. template <class T,
  910.           class V,
  911.           class D = std::ptrdiff_t,
  912.           class P = V*,
  913.           class R = V&>
  914. struct forward_iterator_helper
  915.   : forward_iteratable<T, P
  916.   , std::iterator<std::forward_iterator_tag, V, D, P, R
  917.     > > {};
  918.  
  919. template <class T,
  920.           class V,
  921.           class D = std::ptrdiff_t,
  922.           class P = V*,
  923.           class R = V&>
  924. struct bidirectional_iterator_helper
  925.   : bidirectional_iteratable<T, P
  926.   , std::iterator<std::bidirectional_iterator_tag, V, D, P, R
  927.     > > {};
  928.  
  929. template <class T,
  930.           class V,
  931.           class D = std::ptrdiff_t,
  932.           class P = V*,
  933.           class R = V&>
  934. struct random_access_iterator_helper
  935.   : random_access_iteratable<T, P, D, R
  936.   , std::iterator<std::random_access_iterator_tag, V, D, P, R
  937.     > >
  938. {
  939.   friend D requires_difference_operator(const T& x, const T& y) {
  940.     return x - y;
  941.   }
  942. }; // random_access_iterator_helper
  943.  
  944. } // namespace mars_boost
  945.  
  946. #if defined(__sgi) && !defined(__GNUC__)
  947. #pragma reset woff 1234
  948. #endif
  949.  
  950. #endif // BOOST_OPERATORS_HPP
  951.  
downloadoperators.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top