ALP User Documentation  0.8.preview
Algebraic Programming User Documentation
Classes | Functions
grb::utils::iterators Namespace Reference

Collects various useful STL-compatible iterators. More...

Classes

class  Adapter
 An iterator that simply adapts the values returned by another iterator. More...
 
class  IteratorFilter
 This iterator filters elements from another iterator based on a user- specified filter function. More...
 
class  Repeater
 An iterator that repeats the same value for a set number of times. More...
 
class  Sequence
 An iterator over a collection of \( c \) items that for each item \( i \in \{0,1,\dots,c-1\} \) returns \( f(i) \), where \( f \) is of the form \( o + s( \lfloor i/r \rfloor ) \). More...
 

Functions

template<typename SubIterT >
static Adapter< SubIterT > make_adapter_iterator (const SubIterT start, const SubIterT end, const std::function< typename SubIterT::value_type(const typename SubIterT::value_type) > func)
 Creates an adapter of a given iterator. More...
 
template<typename FwdSubIter >
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 iterator. More...
 

Detailed Description

Collects various useful STL-compatible iterators.

Function Documentation

◆ make_adapter_iterator()

static Adapter< SubIterT > grb::utils::iterators::make_adapter_iterator ( const SubIterT  start,
const SubIterT  end,
const std::function< typename SubIterT::value_type(const typename SubIterT::value_type) >  func 
)
static

Creates an adapter of a given iterator.

Template Parameters
SubIterTThe type of the given iterator.
Warning
Not all iterator categories are presently supported.

Only random random access iterators are currently supported.

Parameters
[in]startThe given iterator whose values shall be adapted.
[in]endThe end-iterator that matches start.
[in]funcThe function by which the values of the given iterator shall be adapted. The function must take a single const value of the iterator value type, and shall return the modified value type.
Returns
An iterator in the same position as start but whose values will be modified according to func.

The returned iterator is a const-iterator, meaning the values iterated over cannot be modified– even if the original iterator supported this.

The iterator adapter does not support changing the original value type of the underlying start and end iterators. If such functionality would be useful, please submit a feature request.

◆ make_filtered_iterator()

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 iterator.

Parameters
[in]beginAn iterator over the same container as end.
[in]endAn iterator over the same container as begin in end position.
[in]funcValues between begin and end for which this function evaluates true shall not be iterated over by the returned IteratorFilter instances.
Returns
An grb::utils::iterators::IteratorFilter instance, matching the first iterator position from begin onwards for which func evaluates false or equals end.
Note
If all elements from begin to end in the underlying collection are to be filtered according to func, then the returned iterator will match end, indicative of the resulting empty set.