• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  (C) Copyright Jeremy Siek 1999.
2 //  Distributed under the Boost Software License, Version 1.0. (See
3 //  accompanying file LICENSE_1_0.txt or copy at
4 //  http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef BOOST_INT_ITERATOR_H
7 #define BOOST_INT_ITERATOR_H
8 
9 #if !defined BOOST_MSVC
10 #include <boost/operators.hpp>
11 #endif
12 #include <iostream>
13 #include <iterator>
14 #include <cstddef>
15 //using namespace std;
16 
17 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
18 namespace boost {
19 namespace iterators {
20 #endif
21 
22 // this should use random_access_iterator_helper but I've had
23 // VC++ portablility problems with that. -JGS
24 template <class IntT>
25 class int_iterator
26 {
27   typedef int_iterator self;
28 public:
29   typedef std::random_access_iterator_tag iterator_category;
30   typedef IntT value_type;
31   typedef IntT& reference;
32   typedef IntT* pointer;
33   typedef std::ptrdiff_t difference_type;
34 
int_iterator()35   inline int_iterator() : _i(0) { }
int_iterator(IntT i)36   inline int_iterator(IntT i) : _i(i) { }
int_iterator(const self & x)37   inline int_iterator(const self& x) : _i(x._i) { }
operator =(const self & x)38   inline self& operator=(const self& x) { _i = x._i; return *this; }
operator *()39   inline IntT operator*() { return _i; }
operator [](IntT n)40   inline IntT operator[](IntT n) { return _i + n; }
operator ++()41   inline self& operator++() { ++_i; return *this; }
operator ++(int)42   inline self operator++(int) { self t = *this; ++_i; return t; }
operator +=(IntT n)43   inline self& operator+=(IntT n) { _i += n; return *this; }
operator +(IntT n)44   inline self operator+(IntT n) { self t = *this; t += n; return t; }
operator --()45   inline self& operator--() { --_i; return *this; }
operator --(int)46   inline self operator--(int) { self t = *this; --_i; return t; }
operator -=(IntT n)47   inline self& operator-=(IntT n) { _i -= n; return *this; }
operator -(const self & x) const48   inline IntT operator-(const self& x) const { return _i - x._i; }
operator ==(const self & x) const49   inline bool operator==(const self& x) const { return _i == x._i; }
50   // vc++ had a problem finding != in random_access_iterator_helper
51   // need to look into this... for now implementing everything here -JGS
operator !=(const self & x) const52   inline bool operator!=(const self& x) const { return _i != x._i; }
operator <(const self & x) const53   inline bool operator<(const self& x) const { return _i < x._i; }
operator <=(const self & x) const54   inline bool operator<=(const self& x) const { return _i <= x._i; }
operator >(const self & x) const55   inline bool operator>(const self& x) const { return _i > x._i; }
operator >=(const self & x) const56   inline bool operator>=(const self& x) const { return _i >= x._i; }
57 protected:
58   IntT _i;
59 };
60 
61 template <class IntT>
62 inline int_iterator<IntT>
operator +(IntT n,int_iterator<IntT> t)63 operator+(IntT n, int_iterator<IntT> t) { t += n; return t; }
64 
65 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
66 } /* namespace iterators */
67 
68 using iterators::int_iterator;
69 
70 } /* namespace boost */
71 #endif
72 
73 #ifdef BOOST_NO_OPERATORS_IN_NAMESPACE
74 namespace boost {
75 using ::int_iterator;
76 namespace iterators {
77 using ::int_iterator;
78 }}
79 #endif
80 
81 
82 #endif /* BOOST_INT_ITERATOR_H */
83