42 #ifndef TEUCHOS_FILTERED_ITERATOR_HPP
43 #define TEUCHOS_FILTERED_ITERATOR_HPP
46 #include "Teuchos_Assert.hpp"
48 #include "Teuchos_Exceptions.hpp"
59 template<
class IteratorType,
class Predicate>
69 typedef typename std::iterator_traits<IteratorType>::value_type
value_type;
71 typedef typename std::iterator_traits<IteratorType>::reference
reference;
73 typedef typename std::iterator_traits<IteratorType>::pointer
pointer;
75 typedef typename std::iterator_traits<IteratorType>::difference_type
difference_type;
89 Predicate pred_in = Predicate()
91 :current_(current_in), begin_(begin_in), end_(end_in), pred_(pred_in)
92 { advanceForwardToValid(); }
94 template<
class IteratorType2,
class Predicate2>
99 template<
class IteratorType2,
class Predicate2>
103 begin_ = rhs.
begin();
116 {
return *current_; }
119 {
return current_.operator->(); }
129 assertNotIterateForwardPastEnd();
131 advanceForwardToValid();
144 assertNotIterateBackwardPastBegin();
146 advanceBackwardToValid();
163 IteratorType
current()
const {
return current_; }
165 IteratorType
begin()
const {
return begin_; }
167 IteratorType
end()
const {
return end_; }
169 Predicate
pred()
const{
return pred_; }
176 IteratorType current_;
187 void advanceForwardToValid();
189 void advanceBackwardToValid();
191 void assertNotIterateForwardPastEnd()
192 #ifndef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
198 void assertNotIterateBackwardPastBegin()
199 #ifndef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
211 template<
class IteratorType,
class Predicate>
222 template<
class IteratorType,
class Predicate>
236 template<
class IteratorType,
class Predicate>
248 template<
class IteratorType,
class Predicate>
251 while (current_ != end_ && !pred_(*current_)) {
257 template<
class IteratorType,
class Predicate>
258 void FilteredIterator<IteratorType,Predicate>::advanceBackwardToValid()
260 while (current_ != begin_ && !pred_(*current_)) {
266 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
269 template<
class IteratorType,
class Predicate>
270 void FilteredIterator<IteratorType,Predicate>::assertNotIterateForwardPastEnd()
272 const bool current_is_at_end = (current_ == end_);
274 "Error, trying to iterate " << *
this <<
" forward ++ past end!");
278 template<
class IteratorType,
class Predicate>
279 void FilteredIterator<IteratorType,Predicate>::assertNotIterateBackwardPastBegin()
281 const bool current_is_at_begin = (current_ == begin_);
283 "Error, trying to iterate " << *
this <<
" backward -- past begin!");
287 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
293 #endif // TEUCHOS_FILTERED_ITERATOR_HPP