Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/next_prior.hpp @ 101:c530137014c0
Update Boost headers (1.58.0)
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:12:49 +0100 |
parents | 2665513ce2d3 |
children |
comparison
equal
deleted
inserted
replaced
100:793467b5e61c | 101:c530137014c0 |
---|---|
11 | 11 |
12 #ifndef BOOST_NEXT_PRIOR_HPP_INCLUDED | 12 #ifndef BOOST_NEXT_PRIOR_HPP_INCLUDED |
13 #define BOOST_NEXT_PRIOR_HPP_INCLUDED | 13 #define BOOST_NEXT_PRIOR_HPP_INCLUDED |
14 | 14 |
15 #include <iterator> | 15 #include <iterator> |
16 #if defined(_MSC_VER) && _MSC_VER <= 1310 | |
17 #include <boost/mpl/and.hpp> | |
18 #include <boost/type_traits/is_integral.hpp> | |
19 #endif | |
20 #include <boost/type_traits/is_unsigned.hpp> | |
21 #include <boost/type_traits/integral_promotion.hpp> | |
22 #include <boost/type_traits/make_signed.hpp> | |
23 #include <boost/type_traits/has_plus.hpp> | |
24 #include <boost/type_traits/has_plus_assign.hpp> | |
25 #include <boost/type_traits/has_minus.hpp> | |
26 #include <boost/type_traits/has_minus_assign.hpp> | |
16 | 27 |
17 namespace boost { | 28 namespace boost { |
18 | 29 |
19 // Helper functions for classes like bidirectional iterators not supporting | 30 // Helper functions for classes like bidirectional iterators not supporting |
20 // operator+ and operator- | 31 // operator+ and operator- |
24 // const std::list<T>::iterator prev = boost::prior(p); | 35 // const std::list<T>::iterator prev = boost::prior(p); |
25 // const std::list<T>::iterator next = boost::next(prev, 2); | 36 // const std::list<T>::iterator next = boost::next(prev, 2); |
26 | 37 |
27 // Contributed by Dave Abrahams | 38 // Contributed by Dave Abrahams |
28 | 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 | |
84 bool IsUInt = is_unsigned< PromotedDistance >::value | |
85 #else | |
86 // MSVC 7.1 has problems with applying is_unsigned to non-integral types | |
87 bool IsUInt = mpl::and_< is_integral< PromotedDistance >, is_unsigned< PromotedDistance > >::value | |
88 #endif | |
89 > | |
90 struct prior_impl3 | |
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 | |
29 template <class T> | 145 template <class T> |
30 inline T next(T x) { return ++x; } | 146 inline T next(T x) { return ++x; } |
31 | 147 |
32 template <class T, class Distance> | 148 template <class T, class Distance> |
33 inline T next(T x, Distance n) | 149 inline T next(T x, Distance n) |
34 { | 150 { |
35 std::advance(x, n); | 151 return next_prior_detail::next_impl1< T, Distance >::call(x, n); |
36 return x; | |
37 } | 152 } |
38 | 153 |
39 template <class T> | 154 template <class T> |
40 inline T prior(T x) { return --x; } | 155 inline T prior(T x) { return --x; } |
41 | 156 |
42 template <class T, class Distance> | 157 template <class T, class Distance> |
43 inline T prior(T x, Distance n) | 158 inline T prior(T x, Distance n) |
44 { | 159 { |
45 std::advance(x, -n); | 160 return next_prior_detail::prior_impl1< T, Distance >::call(x, n); |
46 return x; | |
47 } | 161 } |
48 | 162 |
49 } // namespace boost | 163 } // namespace boost |
50 | 164 |
51 #endif // BOOST_NEXT_PRIOR_HPP_INCLUDED | 165 #endif // BOOST_NEXT_PRIOR_HPP_INCLUDED |