summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--include/opkele/iterator.h5
1 files changed, 0 insertions, 5 deletions
diff --git a/include/opkele/iterator.h b/include/opkele/iterator.h
index 94da7e4..9e5b196 100644
--- a/include/opkele/iterator.h
+++ b/include/opkele/iterator.h
@@ -114,101 +114,96 @@ namespace opkele {
114 return **I; } 114 return **I; }
115 TP operator->() const { 115 TP operator->() const {
116 return I->operator->(); } 116 return I->operator->(); }
117 117
118 forward_iterator_proxy<T,TR,TP>& operator++() { 118 forward_iterator_proxy<T,TR,TP>& operator++() {
119 I->advance(); return *this; } 119 I->advance(); return *this; }
120 forward_iterator_proxy<T,TR,TP>& operator++(int) { 120 forward_iterator_proxy<T,TR,TP>& operator++(int) {
121 forward_iterator_proxy<T,TR,TP> rv(*this); 121 forward_iterator_proxy<T,TR,TP> rv(*this);
122 I->advance(); return rv; } 122 I->advance(); return rv; }
123 }; 123 };
124 124
125 template<typename IT> 125 template<typename IT>
126 class basic_filterator : public iterator< 126 class basic_filterator : public iterator<
127 typename IT::iterator_category, 127 typename IT::iterator_category,
128 typename IT::value_type, 128 typename IT::value_type,
129 typename IT::difference_type, 129 typename IT::difference_type,
130 typename IT::pointer, 130 typename IT::pointer,
131 typename IT::reference> { 131 typename IT::reference> {
132 public: 132 public:
133 IT it; 133 IT it;
134 IT ei; 134 IT ei;
135 bool empty; 135 bool empty;
136 136
137 basic_filterator() : empty(true) { } 137 basic_filterator() : empty(true) { }
138 basic_filterator(const IT& _bi,const IT& _ei) 138 basic_filterator(const IT& _bi,const IT& _ei)
139 : it(_bi), ei(_ei) { empty = (it==ei); } 139 : it(_bi), ei(_ei) { empty = (it==ei); }
140 basic_filterator(const basic_filterator<IT>& x) 140 basic_filterator(const basic_filterator<IT>& x)
141 : it(x.it), ei(x.ei), empty(x.empty) { } 141 : it(x.it), ei(x.ei), empty(x.empty) { }
142 virtual ~basic_filterator() { } 142 virtual ~basic_filterator() { }
143 143
144 bool operator==(const basic_filterator<IT>& x) const { 144 bool operator==(const basic_filterator<IT>& x) const {
145 return empty?x.empty:(it==x.it); } 145 return empty?x.empty:(it==x.it); }
146 bool operator!=(const basic_filterator<IT>& x) const { 146 bool operator!=(const basic_filterator<IT>& x) const {
147 return empty!=x.empty || it!=x.it; } 147 return empty!=x.empty || it!=x.it; }
148 148
149 typename IT::reference operator*() const { 149 typename IT::reference operator*() const {
150 assert(!empty); 150 assert(!empty);
151 return *it; } 151 return *it; }
152 typename IT::pointer operator->() const { 152 typename IT::pointer operator->() const {
153 assert(!empty); 153 assert(!empty);
154 return it.operator->(); } 154 return it.operator->(); }
155 155
156 basic_filterator<IT>& operator++() { 156 basic_filterator<IT>& operator++() {
157 bool found = false; 157 bool found = false;
158 for(++it;!(it==ei || (found=is_interesting()));++it) ; 158 for(++it;!(it==ei || (found=is_interesting()));++it) ;
159 if(!found) empty=true; 159 if(!found) empty=true;
160 return *this; 160 return *this;
161 } 161 }
162 basic_filterator<IT> operator++(int) {
163 basic_filterator<IT> rv(*this);
164 ++(*this);
165 return rv;
166 }
167 162
168 void prepare() { 163 void prepare() {
169 bool found = false; 164 bool found = false;
170 for(;!(it==ei || (found=is_interesting()));++it) ; 165 for(;!(it==ei || (found=is_interesting()));++it) ;
171 if(!found) empty = true; 166 if(!found) empty = true;
172 } 167 }
173 virtual bool is_interesting() const = 0; 168 virtual bool is_interesting() const = 0;
174 }; 169 };
175 170
176 template<typename IT,typename T=typename IT::value_type::first_type,typename TR=T&,typename TP=T*> 171 template<typename IT,typename T=typename IT::value_type::first_type,typename TR=T&,typename TP=T*>
177 class map_keys_iterator : public iterator< 172 class map_keys_iterator : public iterator<
178 typename IT::iterator_category, 173 typename IT::iterator_category,
179 T,void,TP,TR> { 174 T,void,TP,TR> {
180 public: 175 public:
181 typedef map_keys_iterator<IT,T,TR,TP> self_type; 176 typedef map_keys_iterator<IT,T,TR,TP> self_type;
182 IT it; 177 IT it;
183 IT ei; 178 IT ei;
184 bool empty; 179 bool empty;
185 180
186 map_keys_iterator() : empty(true) { } 181 map_keys_iterator() : empty(true) { }
187 map_keys_iterator(const IT& _bi, 182 map_keys_iterator(const IT& _bi,
188 const IT& _ei) 183 const IT& _ei)
189 : it(_bi), ei(_ei) { empty = (it==ei); } 184 : it(_bi), ei(_ei) { empty = (it==ei); }
190 map_keys_iterator(const self_type& x) 185 map_keys_iterator(const self_type& x)
191 : it(x.it), ei(x.ei), empty(x.empty) { } 186 : it(x.it), ei(x.ei), empty(x.empty) { }
192 187
193 bool operator==(const self_type& x) const { 188 bool operator==(const self_type& x) const {
194 return empty?x.empty:(it==x.it); } 189 return empty?x.empty:(it==x.it); }
195 bool operator!=(const self_type& x) const { 190 bool operator!=(const self_type& x) const {
196 return empty!=x.empty || it!=x.it; } 191 return empty!=x.empty || it!=x.it; }
197 192
198 TR operator*() const { 193 TR operator*() const {
199 assert(!empty); 194 assert(!empty);
200 return it->first; } 195 return it->first; }
201 TP operator->() const { 196 TP operator->() const {
202 assert(!empty); 197 assert(!empty);
203 return &(it->first); } 198 return &(it->first); }
204 199
205 self_type& operator++() { 200 self_type& operator++() {
206 assert(!empty); 201 assert(!empty);
207 empty=((++it)==ei); return *this; } 202 empty=((++it)==ei); return *this; }
208 self_type operator++(int) { 203 self_type operator++(int) {
209 self_type rv(*this); 204 self_type rv(*this);
210 ++(*this); return rv; } 205 ++(*this); return rv; }
211 }; 206 };
212 207
213 } 208 }
214} 209}