Extended next/prior using patch from Daniel Walker (Daniel.Walker-at-bowneglobal.com)

[SVN r21382]
This commit is contained in:
Dave Abrahams
2003-12-23 14:59:59 +00:00
committed by Andrey Semashev
parent 5ba5f2c2d4
commit a4bacb5077
2 changed files with 99 additions and 0 deletions

View File

@ -8,9 +8,14 @@
// See http://www.boost.org/libs/utility for documentation.
// Revision History
// 13 Dec 2003 Added next(x, n) and prior(x, n) (Daniel Walker)
#ifndef BOOST_NEXT_PRIOR_HPP_INCLUDED
#define BOOST_NEXT_PRIOR_HPP_INCLUDED
#include <iterator>
namespace boost {
// Helper functions for classes like bidirectional iterators not supporting
@ -19,15 +24,30 @@ namespace boost {
// Usage:
// const std::list<T>::iterator p = get_some_iterator();
// const std::list<T>::iterator prev = boost::prior(p);
// const std::list<T>::iterator next = boost::next(prev, 2);
// Contributed by Dave Abrahams
template <class T>
inline T next(T x) { return ++x; }
template <class T, class Distance>
inline T next(T x, Distance n)
{
std::advance(x, n);
return x;
}
template <class T>
inline T prior(T x) { return --x; }
template <class T, class Distance>
inline T prior(T x, Distance n)
{
std::advance(x, -n);
return x;
}
} // namespace boost
#endif // BOOST_NEXT_PRIOR_HPP_INCLUDED