1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
| #ifndef MY_ITERATOR_H #define MY_ITERATOR_H namespace pzj { class input_iterator_tag {}; class output_iterator_tag {};
class forward_iterator_tag : public input_iterator_tag {}; class bidirectional_iterator_tag : public forward_iterator_tag {}; class random_iterator_tag : public bidirectional_iterator_tag {};
typedef int ptrdiff_t;
template<class _C, class _Ty,class _D = ptrdiff_t, class _Pointer = _Ty*, class _Reference = _Ty&> struct iterator { typedef _C iterator_category; typedef _Ty value_type; typedef _D difference_type; typedef _Pointer pointer; typedef _Reference reference; };
template<class _Ty, class _D> struct _Forit : public iterator<forward_iterator_tag, _Ty, _D> {}; template<class _Ty, class _D> struct _Bidit : public iterator<bidirectional_iterator_tag, _Ty,_D> {}; template<class _Ty, class _D> struct _Randit : public iterator<random_iterator_tag, _Ty, _D> {};
template<class _Iterator> class iterator_traits { public: iterator_traits() {} typedef typename _Iterator::iterator_category iterator_category; typedef typename _Iterator::value_type value_type; typedef typename _Iterator::difference_type difference_type; typedef typename _Iterator::pointer pointer; typedef typename _Iterator::reference reference; }; template<class T> class iterator_traits<T*> { public: iterator_traits() {} typedef typename random_iterator_tag iterator_category; typedef typename T value_type; typedef typename int difference_type; typedef typename T* pointer; typedef typename T& reference; }; template<class T> class iterator_traits<const T*> { public: iterator_traits() {} typedef typename random_iterator_tag iterator_category; typedef typename T value_type; typedef typename int difference_type; typedef typename const T* pointer; typedef typename const T& reference; }; template<class _It> inline typename iterator_traits<_It>::iterator_category Iterator_category(_It it) { typedef typename iterator_traits<_It>::iterator_category iter_cate; return iter_cate(); } template<class _It> inline typename iterator_traits<_It>::value_type* value_type(_It it) { typedef typename iterator_traits<_It>::value_type* _pointer; return static_cast<_pointer>(0); } template<class _It> inline typename iterator_traits<_It>::different_type* different_type(_It it) { typedef typename iterator_traits<_It>::different_type* _different_type; return static_cast<_different_type>(0); } template<class _II, class _D> inline void __advance(_II& it, _D n, input_iterator_tag) {
} template<class _BI, class _D> inline void __advance(_BI& it, _D n, bidirectional_iterator_tag) {
} template<class _RI, class _D> inline void __advance(_RI& it, _D n, random_iterator_tag) { }
template<class _II, class _D> inline void advance(_II& it, _D n) { typedef typename iterator_traits<_II>::iterator_category iter_cate; __advance(it, n, iter_cate()); }
template<class _II> inline typename iterator_traits<_II>::difference_type __distance(_II first, _II last, input_iterator_tag) { typename iterator_traits<_II>::difference_type _dist = 0; while (first != last) { ++first; ++_dist; } return _dist; } template<class _RAI> inline typename iterator_traits<_RAI>::difference_type __distance(_RAI first, _RAI last, random_iterator_tag) { return last - first; }
template< class InputIt > typename iterator_traits<InputIt>::difference_type distance(InputIt first, InputIt last) { __distance(first, last, Iterator_category(first)); } } #endif
|