[857] | 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 | #include <boost/iterator.hpp>
|
---|
| 10 | #if !defined BOOST_MSVC
|
---|
| 11 | #include <boost/operators.hpp>
|
---|
| 12 | #endif
|
---|
| 13 | #include <iostream>
|
---|
| 14 | //using namespace std;
|
---|
| 15 |
|
---|
| 16 | #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
---|
| 17 | namespace boost {
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | // this should use random_access_iterator_helper but I've had
|
---|
| 21 | // VC++ portablility problems with that. -JGS
|
---|
| 22 | template <class IntT>
|
---|
| 23 | class int_iterator
|
---|
| 24 | {
|
---|
| 25 | typedef int_iterator self;
|
---|
| 26 | public:
|
---|
| 27 | typedef std::random_access_iterator_tag iterator_category;
|
---|
| 28 | typedef IntT value_type;
|
---|
| 29 | typedef IntT& reference;
|
---|
| 30 | typedef IntT* pointer;
|
---|
| 31 | typedef std::ptrdiff_t difference_type;
|
---|
| 32 |
|
---|
| 33 | inline int_iterator() : _i(0) { }
|
---|
| 34 | inline int_iterator(IntT i) : _i(i) { }
|
---|
| 35 | inline int_iterator(const self& x) : _i(x._i) { }
|
---|
| 36 | inline self& operator=(const self& x) { _i = x._i; return *this; }
|
---|
| 37 | inline IntT operator*() { return _i; }
|
---|
| 38 | inline IntT operator[](IntT n) { return _i + n; }
|
---|
| 39 | inline self& operator++() { ++_i; return *this; }
|
---|
| 40 | inline self operator++(int) { self t = *this; ++_i; return t; }
|
---|
| 41 | inline self& operator+=(IntT n) { _i += n; return *this; }
|
---|
| 42 | inline self operator+(IntT n) { self t = *this; t += n; return t; }
|
---|
| 43 | inline self& operator--() { --_i; return *this; }
|
---|
| 44 | inline self operator--(int) { self t = *this; --_i; return t; }
|
---|
| 45 | inline self& operator-=(IntT n) { _i -= n; return *this; }
|
---|
| 46 | inline IntT operator-(const self& x) const { return _i - x._i; }
|
---|
| 47 | inline bool operator==(const self& x) const { return _i == x._i; }
|
---|
| 48 | // vc++ had a problem finding != in random_access_iterator_helper
|
---|
| 49 | // need to look into this... for now implementing everything here -JGS
|
---|
| 50 | inline bool operator!=(const self& x) const { return _i != x._i; }
|
---|
| 51 | inline bool operator<(const self& x) const { return _i < x._i; }
|
---|
| 52 | inline bool operator<=(const self& x) const { return _i <= x._i; }
|
---|
| 53 | inline bool operator>(const self& x) const { return _i > x._i; }
|
---|
| 54 | inline bool operator>=(const self& x) const { return _i >= x._i; }
|
---|
| 55 | protected:
|
---|
| 56 | IntT _i;
|
---|
| 57 | };
|
---|
| 58 |
|
---|
| 59 | template <class IntT>
|
---|
| 60 | inline int_iterator<IntT>
|
---|
| 61 | operator+(IntT n, int_iterator<IntT> t) { t += n; return t; }
|
---|
| 62 |
|
---|
| 63 | #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
---|
| 64 | } /* namespace boost */
|
---|
| 65 | #endif
|
---|
| 66 |
|
---|
| 67 | #ifdef BOOST_NO_OPERATORS_IN_NAMESPACE
|
---|
| 68 | namespace boost {
|
---|
| 69 | using ::int_iterator;
|
---|
| 70 | }
|
---|
| 71 | #endif
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | #endif /* BOOST_INT_ITERATOR_H */
|
---|