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;
92 { advanceForwardToValid(); }
94 template<
class IteratorType2,
class Predicate2>
99 template<
class IteratorType2,
class Predicate2>
102 current_ = rhs.current();
103 begin_ = rhs.begin();
116 {
return *current_; }
119 {
return current_.operator->(); }
129 assertNotIterateForwardPastEnd();
131 advanceForwardToValid();
144 assertNotIterateBackwardPastBegin();
146 advanceBackwardToValid();
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>
215 return itr1.current() ==
itr2.current();
222template<
class IteratorType,
class Predicate>
226 return itr1.current() !=
itr2.current();
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()
274 "Error, trying to iterate " << *
this <<
" forward ++ past end!");
278template<
class IteratorType,
class Predicate>
279void FilteredIterator<IteratorType,Predicate>::assertNotIterateBackwardPastBegin()
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.
Smart reference counting pointer class for automatic garbage collection.
RCP(ENull null_arg=null)
Initialize RCP<T> to NULL.
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,...