123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- #ifndef BOOST_NEXT_PRIOR_HPP_INCLUDED
- #define BOOST_NEXT_PRIOR_HPP_INCLUDED
- #include <boost/config.hpp>
- #include <boost/type_traits/has_plus.hpp>
- #include <boost/type_traits/has_plus_assign.hpp>
- #include <boost/type_traits/has_minus.hpp>
- #include <boost/type_traits/has_minus_assign.hpp>
- #include <boost/iterator/is_iterator.hpp>
- #include <boost/iterator/advance.hpp>
- #include <boost/iterator/reverse_iterator.hpp>
- namespace boost {
- namespace next_prior_detail {
- template< typename T, typename Distance, bool HasPlus = has_plus< T, Distance >::value >
- struct next_plus_impl;
- template< typename T, typename Distance >
- struct next_plus_impl< T, Distance, true >
- {
- static T call(T x, Distance n)
- {
- return x + n;
- }
- };
- template< typename T, typename Distance, bool HasPlusAssign = has_plus_assign< T, Distance >::value >
- struct next_plus_assign_impl :
- public next_plus_impl< T, Distance >
- {
- };
- template< typename T, typename Distance >
- struct next_plus_assign_impl< T, Distance, true >
- {
- static T call(T x, Distance n)
- {
- x += n;
- return x;
- }
- };
- template< typename T, typename Distance, bool IsIterator = boost::iterators::is_iterator< T >::value >
- struct next_advance_impl :
- public next_plus_assign_impl< T, Distance >
- {
- };
- template< typename T, typename Distance >
- struct next_advance_impl< T, Distance, true >
- {
- static T call(T x, Distance n)
- {
- boost::iterators::advance(x, n);
- return x;
- }
- };
- template< typename T, typename Distance, bool HasMinus = has_minus< T, Distance >::value >
- struct prior_minus_impl;
- template< typename T, typename Distance >
- struct prior_minus_impl< T, Distance, true >
- {
- static T call(T x, Distance n)
- {
- return x - n;
- }
- };
- template< typename T, typename Distance, bool HasMinusAssign = has_minus_assign< T, Distance >::value >
- struct prior_minus_assign_impl :
- public prior_minus_impl< T, Distance >
- {
- };
- template< typename T, typename Distance >
- struct prior_minus_assign_impl< T, Distance, true >
- {
- static T call(T x, Distance n)
- {
- x -= n;
- return x;
- }
- };
- template< typename T, typename Distance, bool IsIterator = boost::iterators::is_iterator< T >::value >
- struct prior_advance_impl :
- public prior_minus_assign_impl< T, Distance >
- {
- };
- template< typename T, typename Distance >
- struct prior_advance_impl< T, Distance, true >
- {
- static T call(T x, Distance n)
- {
-
- boost::iterators::reverse_iterator< T > rx(x);
- boost::iterators::advance(rx, n);
- return rx.base();
- }
- };
- }
- template <class T>
- inline T next(T x) { return ++x; }
- template <class T, class Distance>
- inline T next(T x, Distance n)
- {
- return next_prior_detail::next_advance_impl< T, Distance >::call(x, n);
- }
- template <class T>
- inline T prior(T x) { return --x; }
- template <class T, class Distance>
- inline T prior(T x, Distance n)
- {
- return next_prior_detail::prior_advance_impl< T, Distance >::call(x, n);
- }
- }
- #endif
|