10#ifndef TEUCHOS_FILTERED_ITERATOR_HPP
11#define TEUCHOS_FILTERED_ITERATOR_HPP
14#include "Teuchos_Assert.hpp"
16#include "Teuchos_Exceptions.hpp"
27template<
class IteratorType,
class Predicate>
37 typedef typename std::iterator_traits<IteratorType>::value_type
value_type;
39 typedef typename std::iterator_traits<IteratorType>::reference
reference;
41 typedef typename std::iterator_traits<IteratorType>::pointer
pointer;
43 typedef typename std::iterator_traits<IteratorType>::difference_type
difference_type;
60 { advanceForwardToValid(); }
62 template<
class IteratorType2,
class Predicate2>
67 template<
class IteratorType2,
class Predicate2>
70 current_ = rhs.current();
87 {
return current_.operator->(); }
97 assertNotIterateForwardPastEnd();
99 advanceForwardToValid();
112 assertNotIterateBackwardPastBegin();
114 advanceBackwardToValid();
155 void advanceForwardToValid();
157 void advanceBackwardToValid();
159 void assertNotIterateForwardPastEnd()
160#ifndef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
166 void assertNotIterateBackwardPastBegin()
167#ifndef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
179template<
class IteratorType,
class Predicate>
183 return itr1.current() ==
itr2.current();
190template<
class IteratorType,
class Predicate>
194 return itr1.current() !=
itr2.current();
204template<
class IteratorType,
class Predicate>
216template<
class IteratorType,
class Predicate>
219 while (current_ != end_ && !pred_(*current_)) {
225template<
class IteratorType,
class Predicate>
226void FilteredIterator<IteratorType,Predicate>::advanceBackwardToValid()
228 while (current_ != begin_ && !pred_(*current_)) {
234#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
237template<
class IteratorType,
class Predicate>
238void FilteredIterator<IteratorType,Predicate>::assertNotIterateForwardPastEnd()
240 const bool current_is_at_end = (current_ == end_);
242 "Error, trying to iterate " << *
this <<
" forward ++ past end!");
246template<
class IteratorType,
class Predicate>
247void FilteredIterator<IteratorType,Predicate>::assertNotIterateBackwardPastBegin()
249 const bool current_is_at_begin = (current_ == begin_);
251 "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.
Smart reference counting pointer class for automatic garbage collection.
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,...