42#ifndef TEUCHOS_FILTERED_ITERATOR_HPP
43#define TEUCHOS_FILTERED_ITERATOR_HPP
46#include "Teuchos_Assert.hpp"
48#include "Teuchos_Exceptions.hpp"
59template<
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
211template<
class IteratorType,
class Predicate>
222template<
class IteratorType,
class Predicate>
236template<
class IteratorType,
class Predicate>
248template<
class IteratorType,
class Predicate>
251 while (current_ != end_ && !pred_(*current_)) {
257template<
class IteratorType,
class Predicate>
258void FilteredIterator<IteratorType,Predicate>::advanceBackwardToValid()
260 while (current_ != begin_ && !pred_(*current_)) {
266#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
269template<
class IteratorType,
class Predicate>
270void FilteredIterator<IteratorType,Predicate>::assertNotIterateForwardPastEnd()
272 const bool current_is_at_end = (current_ == end_);
274 "Error, trying to iterate " << *
this <<
" forward ++ past end!");
278template<
class IteratorType,
class Predicate>
279void FilteredIterator<IteratorType,Predicate>::assertNotIterateBackwardPastBegin()
281 const bool current_is_at_begin = (current_ == begin_);
283 "Error, trying to iterate " << *
this <<
" backward -- past begin!");
Defines basic traits returning the name of a type in a portable and readable way.
C++ Standard Library compatable filtered iterator.
std::iterator_traits< IteratorType >::value_type value_type
std::ostream & operator<<(std::ostream &out, const FilteredIterator< IteratorType, Predicate > &itr)
ostream operator.
std::iterator_traits< IteratorType >::reference reference
IteratorType begin() const
FilteredIterator & operator=(const FilteredIterator< IteratorType2, Predicate2 > &rhs)
Assign different types of iterators (mainly for non-const to const).
std::iterator_traits< IteratorType >::difference_type difference_type
reference operator*() const
itr*
FilteredIterator(IteratorType current_in, IteratorType begin_in, IteratorType end_in, Predicate pred_in=Predicate())
Construct with iterator and range.
std::bidirectional_iterator_tag iterator_category
const FilteredIterator operator--(int)
itr–
FilteredIterator(const FilteredIterator< IteratorType2, Predicate2 > &rhs)
Convert type of iterators (mainly for non-const to const).
pointer operator->() const
itr->member
FilteredIterator & operator++()
++itr
FilteredIterator & operator--()
–itr
bool operator!=(const FilteredIterator< IteratorType, Predicate > &itr1, const FilteredIterator< IteratorType, Predicate > &itr2)
itr1 != itr2.
const FilteredIterator operator++(int)
itr++
IteratorType current() const
bool operator==(const FilteredIterator< IteratorType, Predicate > &itr1, const FilteredIterator< IteratorType, Predicate > &itr2)
itr1 == itr2.
std::iterator_traits< IteratorType >::pointer pointer
FilteredIterator()
construct to a null iterator.
static std::string name()
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...