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