A library for working with phylogenetic and population genetic data.
v0.27.0
FilterIterator< PredicateFunctor, BaseIterator > Class Template Reference

#include <genesis/utils/containers/filter_iterator.hpp>

Detailed Description

template<typename PredicateFunctor, typename BaseIterator>
class genesis::utils::FilterIterator< PredicateFunctor, BaseIterator >

Iterator class that allows to filter an underlying iterator by skipping elements that do not satisfy a given predicate.

The constructor is used to set the filter predicate function. See also make_filter_iterator() and make_filter_range() for helper functions to easily create an instance.

Inspired by the Boost Filter Iterator (https://www.boost.org/doc/libs/1_67_0/libs/iterator/doc/html/iterator/specialized/filter.html), StackOverflow (https://stackoverflow.com/a/44350827/4184258), and Jez Higgins (https://www.jezuk.co.uk/blog/2008/02/a-filtering-iterator-in-c.html).

Definition at line 58 of file filter_iterator.hpp.

Public Member Functions

 FilterIterator (FilterIterator &&)=default
 
 FilterIterator (FilterIterator const &)=default
 
 FilterIterator (PredicateFunctor unary_func, BaseIterator begin, BaseIterator end=BaseIterator{})
 Construct a filtering iterator, given the filter predicate function as well as the underlying base iterator begin and end. More...
 
 ~FilterIterator ()=default
 
BaseIterator base () const
 
BaseIterator end () const
 
bool operator!= (FilterIterator const &it) const
 
reference operator* ()
 
const_reference operator* () const
 
FilterIterator operator+ (difference_type n) const
 
FilterIteratoroperator++ ()
 
FilterIterator operator++ (int)
 
FilterIteratoroperator+= (difference_type n)
 
reference operator-> () const
 
bool operator< (FilterIterator const &it) const
 
bool operator<= (FilterIterator const &it) const
 
FilterIteratoroperator= (FilterIterator &&)=default
 
FilterIteratoroperator= (FilterIterator const &)=default
 
bool operator== (FilterIterator const &it) const
 
bool operator> (FilterIterator const &it) const
 
bool operator>= (FilterIterator const &it) const
 

Public Types

using const_reference = typename std::iterator_traits< BaseIterator >::reference const
 
using difference_type = typename std::iterator_traits< BaseIterator >::difference_type
 
using iterator_category = std::input_iterator_tag
 
using pointer = typename std::iterator_traits< BaseIterator >::pointer
 
using reference = typename std::iterator_traits< BaseIterator >::reference
 
using value_type = typename std::iterator_traits< BaseIterator >::value_type
 

Friends

FilterIterator operator+ (difference_type n, FilterIterator const &it)
 

Constructor & Destructor Documentation

◆ FilterIterator() [1/3]

FilterIterator ( PredicateFunctor  unary_func,
BaseIterator  begin,
BaseIterator  end = BaseIterator{} 
)
inline

Construct a filtering iterator, given the filter predicate function as well as the underlying base iterator begin and end.

Caveat: Note that by default, we use a default-constructed end iterator. This only works for containers where the default-constructed iterator is the end iterator! In particular, this does NOT work for many STL containers. For example, for a std::vector, one needs to explicitly use vector.end() here.

This constructor needs to be used for both the begin and end of the range that one wants to iterate, using the same filter function both times. See also make_filter_iterator() and make_filter_range() for helper functions to easily create an instance.

Definition at line 91 of file filter_iterator.hpp.

◆ ~FilterIterator()

~FilterIterator ( )
default

◆ FilterIterator() [2/3]

FilterIterator ( FilterIterator< PredicateFunctor, BaseIterator > const &  )
default

◆ FilterIterator() [3/3]

FilterIterator ( FilterIterator< PredicateFunctor, BaseIterator > &&  )
default

Member Function Documentation

◆ base()

BaseIterator base ( ) const
inline

Definition at line 136 of file filter_iterator.hpp.

◆ end()

BaseIterator end ( ) const
inline

Definition at line 141 of file filter_iterator.hpp.

◆ operator!=()

bool operator!= ( FilterIterator< PredicateFunctor, BaseIterator > const &  it) const
inline

Definition at line 202 of file filter_iterator.hpp.

◆ operator*() [1/2]

reference operator* ( )
inline

Definition at line 121 of file filter_iterator.hpp.

◆ operator*() [2/2]

const_reference operator* ( ) const
inline

Definition at line 126 of file filter_iterator.hpp.

◆ operator+()

FilterIterator operator+ ( difference_type  n) const
inline

Definition at line 163 of file filter_iterator.hpp.

◆ operator++() [1/2]

FilterIterator& operator++ ( )
inline

Definition at line 150 of file filter_iterator.hpp.

◆ operator++() [2/2]

FilterIterator operator++ ( int  )
inline

Definition at line 156 of file filter_iterator.hpp.

◆ operator+=()

FilterIterator& operator+= ( difference_type  n)
inline

Definition at line 171 of file filter_iterator.hpp.

◆ operator->()

reference operator-> ( ) const
inline

Definition at line 131 of file filter_iterator.hpp.

◆ operator<()

bool operator< ( FilterIterator< PredicateFunctor, BaseIterator > const &  it) const
inline

Definition at line 207 of file filter_iterator.hpp.

◆ operator<=()

bool operator<= ( FilterIterator< PredicateFunctor, BaseIterator > const &  it) const
inline

Definition at line 217 of file filter_iterator.hpp.

◆ operator=() [1/2]

FilterIterator& operator= ( FilterIterator< PredicateFunctor, BaseIterator > &&  )
default

◆ operator=() [2/2]

FilterIterator& operator= ( FilterIterator< PredicateFunctor, BaseIterator > const &  )
default

◆ operator==()

bool operator== ( FilterIterator< PredicateFunctor, BaseIterator > const &  it) const
inline

Definition at line 197 of file filter_iterator.hpp.

◆ operator>()

bool operator> ( FilterIterator< PredicateFunctor, BaseIterator > const &  it) const
inline

Definition at line 212 of file filter_iterator.hpp.

◆ operator>=()

bool operator>= ( FilterIterator< PredicateFunctor, BaseIterator > const &  it) const
inline

Definition at line 222 of file filter_iterator.hpp.

Friends And Related Function Documentation

◆ operator+

FilterIterator operator+ ( difference_type  n,
FilterIterator< PredicateFunctor, BaseIterator > const &  it 
)
friend

Definition at line 187 of file filter_iterator.hpp.

Member Typedef Documentation

◆ const_reference

using const_reference = typename std::iterator_traits<BaseIterator>::reference const

Definition at line 70 of file filter_iterator.hpp.

◆ difference_type

using difference_type = typename std::iterator_traits<BaseIterator>::difference_type

Definition at line 72 of file filter_iterator.hpp.

◆ iterator_category

using iterator_category = std::input_iterator_tag

Definition at line 66 of file filter_iterator.hpp.

◆ pointer

using pointer = typename std::iterator_traits<BaseIterator>::pointer

Definition at line 71 of file filter_iterator.hpp.

◆ reference

using reference = typename std::iterator_traits<BaseIterator>::reference

Definition at line 69 of file filter_iterator.hpp.

◆ value_type

using value_type = typename std::iterator_traits<BaseIterator>::value_type

Definition at line 68 of file filter_iterator.hpp.


The documentation for this class was generated from the following file: