fix doc example typo
[boost.git] / boost / next_prior.hpp
blobe1d2e42891976c678a5bd5fe1f1ba86526346e7d
1 // Boost next_prior.hpp header file ---------------------------------------//
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)
7 // See http://www.boost.org/libs/utility for documentation.
9 // Revision History
10 // 13 Dec 2003 Added next(x, n) and prior(x, n) (Daniel Walker)
12 #ifndef BOOST_NEXT_PRIOR_HPP_INCLUDED
13 #define BOOST_NEXT_PRIOR_HPP_INCLUDED
15 #include <iterator>
17 namespace boost {
19 // Helper functions for classes like bidirectional iterators not supporting
20 // operator+ and operator-
22 // Usage:
23 // const std::list<T>::iterator p = get_some_iterator();
24 // const std::list<T>::iterator prev = boost::prior(p);
25 // const std::list<T>::iterator next = boost::next(prev, 2);
27 // Contributed by Dave Abrahams
29 template <class T>
30 inline T next(T x) { return ++x; }
32 template <class T, class Distance>
33 inline T next(T x, Distance n)
35 std::advance(x, n);
36 return x;
39 template <class T>
40 inline T prior(T x) { return --x; }
42 template <class T, class Distance>
43 inline T prior(T x, Distance n)
45 std::advance(x, -n);
46 return x;
49 } // namespace boost
51 #endif // BOOST_NEXT_PRIOR_HPP_INCLUDED