blob: 4e6028004ee154f2fb0769759e920b82497ac70e [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070012#ifndef NDNBOOST_NEXT_PRIOR_HPP_INCLUDED
13#define NDNBOOST_NEXT_PRIOR_HPP_INCLUDED
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070014
15#include <iterator>
16
17namespace ndnboost {
18
19// Helper functions for classes like bidirectional iterators not supporting
20// operator+ and operator-
21//
22// Usage:
23// const std::list<T>::iterator p = get_some_iterator();
24// const std::list<T>::iterator prev = ndnboost::prior(p);
25// const std::list<T>::iterator next = ndnboost::next(prev, 2);
26
27// Contributed by Dave Abrahams
28
29template <class T>
30inline T next(T x) { return ++x; }
31
32template <class T, class Distance>
33inline T next(T x, Distance n)
34{
35 std::advance(x, n);
36 return x;
37}
38
39template <class T>
40inline T prior(T x) { return --x; }
41
42template <class T, class Distance>
43inline T prior(T x, Distance n)
44{
45 std::advance(x, -n);
46 return x;
47}
48
49} // namespace ndnboost
50
Jeff Thompson3d613fd2013-10-15 15:39:04 -070051#endif // NDNBOOST_NEXT_PRIOR_HPP_INCLUDED