27 #ifndef _H_ALP_UTILS_ITERATORS_FILTER 28 #define _H_ALP_UTILS_ITERATORS_FILTER 52 template<
typename FwdSubIter >
75 template<
typename FwdSubIter >
77 FwdSubIter begin,
const FwdSubIter end,
78 const std::function<
bool(
const typename FwdSubIter::value_type &) > func
81 template<
typename FwdSubIter >
84 static_assert( std::is_base_of<
85 std::forward_iterator_tag,
86 typename std::iterator_traits< FwdSubIter >::iterator_category
88 "The sub-iterator to IteratorFilter must be a forward iterator." 95 typedef typename std::iterator_traits< FwdSubIter >::value_type ValT;
98 typedef typename std::function< bool(
const ValT & ) > FilterT;
116 const FwdSubIter end;
133 FwdSubIter it_in,
const FwdSubIter end_in,
134 const FilterT func_in
136 it( it_in ), end( end_in ), filter( func_in )
157 std::swap( left.it, right.it );
158 std::swap( left.end, right.end );
159 std::swap( left.filter, right.filter );
162 template<
typename T >
164 T begin,
const T end,
165 const std::function<
bool(
const typename T::value_type &) > func
170 typedef typename std::iterator_traits< self_type >::difference_type
172 typedef typename std::iterator_traits< self_type >::value_type value_type;
173 typedef typename std::iterator_traits< self_type >::pointer pointer;
175 typedef typename std::iterator_traits< self_type >::iterator_category
192 it( toCopy.it ), end( toCopy.end ), filter( toCopy.filter )
212 filter = toCopy.filter;
230 while( it != end && filter( *it ) ) {
251 while( it != end && filter( *it ) ) {
278 return it.operator->();
293 return it == other.it;
308 return it != other.it;
313 template<
typename FwdSubIter >
315 FwdSubIter begin,
const FwdSubIter end,
316 const std::function<
bool(
const typename FwdSubIter::value_type &) > func
321 while( begin != end && func( *begin ) ) {
345 template<
typename FwdSubIter >
346 struct iterator_traits<
347 grb::utils::iterators::IteratorFilter< FwdSubIter >
351 typedef typename std::iterator_traits< FwdSubIter >::difference_type
355 typedef typename std::iterator_traits< FwdSubIter >::value_type
value_type;
358 typedef typename std::iterator_traits< FwdSubIter >::pointer
pointer;
370 #endif // end _H_ALP_UTILS_ITERATORS_FILTER std::forward_iterator_tag iterator_category
This trait is always forward iterator.
Definition: filter.hpp:364
IteratorFilter< FwdSubIter > & operator=(const IteratorFilter< FwdSubIter > &toCopy)
Copy-assignment.
Definition: filter.hpp:208
std::iterator_traits< FwdSubIter >::pointer pointer
This trait is inherited from FwdSubIter.
Definition: filter.hpp:358
bool operator==(const IteratorFilter< FwdSubIter > &other) const
Equality check.
Definition: filter.hpp:292
This iterator filters elements from another iterator based on a user- specified filter function.
Definition: filter.hpp:53
IteratorFilter(const IteratorFilter< FwdSubIter > &toCopy)
Copy constructor.
Definition: filter.hpp:191
IteratorFilter< FwdSubIter > make_filtered_iterator(FwdSubIter begin, const FwdSubIter end, const std::function< bool(const typename FwdSubIter::value_type &) > func)
The factory function that takes any iterator pair over the same container and returns a filtered iter...
Definition: filter.hpp:314
reference operator*() const
Dereference operator.
Definition: filter.hpp:265
std::iterator_traits< FwdSubIter >::value_type value_type
This trait is inherited from FwdSubIter.
Definition: filter.hpp:355
IteratorFilter()=delete
An IteratorFilter may never be default-constructed.
bool operator!=(const IteratorFilter< FwdSubIter > &other) const
Inequality check.
Definition: filter.hpp:307
pointer operator->() const
Pointer operator.
Definition: filter.hpp:277
The sequential reference implementation.
Definition: backends.hpp:55
std::iterator_traits< FwdSubIter >::difference_type difference_type
This trait is inherited from FwdSubIter.
Definition: filter.hpp:352
~IteratorFilter()
Default destructor.
Definition: filter.hpp:198
IteratorFilter< FwdSubIter > & operator++()
Iterator increment operation.
Definition: filter.hpp:228
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:477
friend void swap(IteratorFilter< FwdSubIter > &left, IteratorFilter< FwdSubIter > &right) noexcept
Swap two instances of the grb::utils::iterators::IteratorFilter type.
Definition: filter.hpp:154
std::iterator_traits< FwdSubIter >::reference reference
This trait is inherited from FwdSubIter.
Definition: filter.hpp:361
IteratorFilter< FwdSubIter > operator++(int)
Iterator increment operation.
Definition: filter.hpp:248