next_prior.hpp
Go to the documentation of this file.
1 // Boost next_prior.hpp header file ---------------------------------------//
2 
3 // (C) Copyright Dave Abrahams and Daniel Walker 1999-2003. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 
7 // See http://www.boost.org/libs/utility for documentation.
8 
9 // Revision History
10 // 13 Dec 2003 Added next(x, n) and prior(x, n) (Daniel Walker)
11 
12 #ifndef BOOST_NEXT_PRIOR_HPP_INCLUDED
13 #define BOOST_NEXT_PRIOR_HPP_INCLUDED
14 
15 #include <iterator>
16 #if defined(_MSC_VER) && _MSC_VER <= 1310
17 #include <boost/mpl/and.hpp>
19 #endif
27 
28 namespace boost {
29 
30 // Helper functions for classes like bidirectional iterators not supporting
31 // operator+ and operator-
32 //
33 // Usage:
34 // const std::list<T>::iterator p = get_some_iterator();
35 // const std::list<T>::iterator prev = boost::prior(p);
36 // const std::list<T>::iterator next = boost::next(prev, 2);
37 
38 // Contributed by Dave Abrahams
39 
40 namespace next_prior_detail {
41 
42 template< typename T, typename Distance, bool HasPlus = has_plus< T, Distance >::value >
43 struct next_impl2
44 {
45  static T call(T x, Distance n)
46  {
47  std::advance(x, n);
48  return x;
49  }
50 };
51 
52 template< typename T, typename Distance >
53 struct next_impl2< T, Distance, true >
54 {
55  static T call(T x, Distance n)
56  {
57  return x + n;
58  }
59 };
60 
61 
62 template< typename T, typename Distance, bool HasPlusAssign = has_plus_assign< T, Distance >::value >
63 struct next_impl1 :
64  public next_impl2< T, Distance >
65 {
66 };
67 
68 template< typename T, typename Distance >
69 struct next_impl1< T, Distance, true >
70 {
71  static T call(T x, Distance n)
72  {
73  x += n;
74  return x;
75  }
76 };
77 
78 
79 template<
80  typename T,
81  typename Distance,
82  typename PromotedDistance = typename integral_promotion< Distance >::type,
83 #if !defined(_MSC_VER) || _MSC_VER > 1310
85 #else
86  // MSVC 7.1 has problems with applying is_unsigned to non-integral types
88 #endif
89 >
91 {
92  static T call(T x, Distance n)
93  {
94  std::advance(x, -n);
95  return x;
96  }
97 };
98 
99 template< typename T, typename Distance, typename PromotedDistance >
100 struct prior_impl3< T, Distance, PromotedDistance, true >
101 {
102  static T call(T x, Distance n)
103  {
104  typedef typename make_signed< PromotedDistance >::type signed_distance;
105  std::advance(x, -static_cast< signed_distance >(static_cast< PromotedDistance >(n)));
106  return x;
107  }
108 };
109 
110 
111 template< typename T, typename Distance, bool HasMinus = has_minus< T, Distance >::value >
112 struct prior_impl2 :
113  public prior_impl3< T, Distance >
114 {
115 };
116 
117 template< typename T, typename Distance >
118 struct prior_impl2< T, Distance, true >
119 {
120  static T call(T x, Distance n)
121  {
122  return x - n;
123  }
124 };
125 
126 
127 template< typename T, typename Distance, bool HasMinusAssign = has_minus_assign< T, Distance >::value >
128 struct prior_impl1 :
129  public prior_impl2< T, Distance >
130 {
131 };
132 
133 template< typename T, typename Distance >
134 struct prior_impl1< T, Distance, true >
135 {
136  static T call(T x, Distance n)
137  {
138  x -= n;
139  return x;
140  }
141 };
142 
143 } // namespace next_prior_detail
144 
145 template <class T>
146 inline T next(T x) { return ++x; }
147 
148 template <class T, class Distance>
149 inline T next(T x, Distance n)
150 {
152 }
153 
154 template <class T>
155 inline T prior(T x) { return --x; }
156 
157 template <class T, class Distance>
158 inline T prior(T x, Distance n)
159 {
161 }
162 
163 } // namespace boost
164 
165 #endif // BOOST_NEXT_PRIOR_HPP_INCLUDED
has_minus.hpp
T
T
Definition: mem_fn_cc.hpp:25
boost::next_prior_detail::next_impl2::call
static T call(T x, Distance n)
Definition: next_prior.hpp:45
boost::next_prior_detail::prior_impl3
Definition: next_prior.hpp:90
boost::next_prior_detail::prior_impl3< T, Distance, PromotedDistance, true >::call
static T call(T x, Distance n)
Definition: next_prior.hpp:102
boost::next_prior_detail::prior_impl1
Definition: next_prior.hpp:128
boost::next_prior_detail::next_impl1< T, Distance, true >::call
static T call(T x, Distance n)
Definition: next_prior.hpp:71
is_unsigned.hpp
boost
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
boost::next_prior_detail::prior_impl2< T, Distance, true >::call
static T call(T x, Distance n)
Definition: next_prior.hpp:120
has_plus.hpp
is_integral.hpp
and.hpp
make_signed.hpp
boost::next_prior_detail::prior_impl1< T, Distance, true >::call
static T call(T x, Distance n)
Definition: next_prior.hpp:136
boost::next_prior_detail::prior_impl3::call
static T call(T x, Distance n)
Definition: next_prior.hpp:92
boost::next_prior_detail::next_impl1
Definition: next_prior.hpp:63
has_minus_assign.hpp
boost::integral_promotion::type
boost::type_traits::detail::integral_promotion< T, tag_type::value >::type type
Definition: integral_promotion.hpp:175
boost::next
T next(T x)
Definition: next_prior.hpp:146
boost::is_unsigned
Definition: is_unsigned.hpp:79
has_plus_assign.hpp
boost::next_prior_detail::next_impl2
Definition: next_prior.hpp:43
boost::next_prior_detail::next_impl2< T, Distance, true >::call
static T call(T x, Distance n)
Definition: next_prior.hpp:55
boost::prior
T prior(T x)
Definition: next_prior.hpp:155
integral_promotion.hpp
boost::mpl::and_
Definition: mpl/aux_/preprocessed/bcc/and.hpp:48
boost::integral_constant
Definition: integral_constant.hpp:52
boost::next_prior_detail::prior_impl2
Definition: next_prior.hpp:112


sick_visionary_ros
Author(s): SICK AG TechSupport 3D Snapshot
autogenerated on Thu Feb 8 2024 03:45:32