KrisLibrary  1.0.0
iteratorutils.h
Go to the documentation of this file.
1 #ifndef ITERATOR_UTILS_H
2 #define ITERATOR_UTILS_H
3 
12 
13 template <class T>
14 inline T increment(const T& a,int n=1)
15 {
16  T x=a;
17  for(int i=0;i<n;i++) ++x;
18  return x;
19 }
20 
21 template <class T>
22 inline T decrement(const T& a,int n=1)
23 {
24  T x=a;
25  for(int i=0;i<n;i++) --x;
26  return x;
27 }
28 
29 //returns a-b, the # of times you'd need to increment b to get to a
30 template <class T>
31 inline int iterator_diff(const T& a,const T& b)
32 {
33  T x=b;
34  int n=0;
35  while(x!=a) { ++x; ++n; }
36  return n;
37 }
38 
41 #endif