Lumiera  0.pre.03
»edit your freedom«
itertools.hpp File Reference

Go to the source code of this file.

Description

Helpers for working with iterators based on the pipeline model.

Iterators abstract from the underlying data container and provide the contained data as a source to pull values from. Based on this model, we can build pipelines, with filters, valves, junction points and transforming facilities. The templates in this header enable such, based on the Lumiera Forward Iterator concept. They build on generic programming techniques, thus are intended to be combined at compile time using definitive type information. Contrast this to an iterator model as in Java's Collections, where Iterator is an Interface based on virtual functions. Thus, the basic problem to overcome is the lack of a single common interface, which could serve as foundation for type inference. As a solution, we use a "onion" approach, where a generic base gets configured with an active core, implementing the filtering or processing functionality, while the base class (IterTool) exposes the operations necessary to comply to the Forward Iterator Concept.

filtering Iterator
The FilterIter template can be used to build a filter into a pipeline, as it forwards only those elements from its source iterator, which pass the predicate evaluation. Anything acceptable as ctor parameter for a std::function object can be passed in as predicate, but of course the signature must be sensible. Please note, that – depending on the predicate – already the ctor or even a simple bool test might pull and exhaust the source iterator completely, in an attempt to find the first element passing the predicate test.
extensible Filter
Based on the FilterIter, this facility allows to elaborate the filter function while in the middle of iteration. The new augmented filter will be in effect starting with the current element, which might even be filtered away now due to a more restrictive condition. However, since this is still an iterator, any "past" elements are already extracted and gone and can thus not be subject to changed filtering. The ExtensibleFilterIter template provides several builder functions to elaborate the initial filter condition, like adding conjunctive or disjunctive clauses, flip the filter's meaning or even replace it altogether by a completely different filter function.
processing Iterator
the TransformIter template can be used as processing (or transforming) step within the pipeline. It is created with a functor, which, when pulling elements, is invoked for each element pulled from the source iterator. The signature of the functor must match the desired value (output) type.
See also
iter-adapter.hpp
itertools-test.cpp
event-log.hpp

Definition in file itertools.hpp.

#include "lib/iter-adapter.hpp"
#include "lib/meta/value-type-binding.hpp"
#include "lib/meta/function.hpp"
#include "lib/meta/trait.hpp"
#include "lib/wrapper.hpp"
#include "lib/util.hpp"
#include <functional>
#include <utility>

Classes

class  ExtensibleFilterIter< IT >
 Additional capabilities for FilterIter, allowing to extend the filter condition underway. More...
 
struct  FilterCore< IT >
 Implementation of the filter logic. More...
 
class  FilterIter< IT >
 Iterator tool filtering pulled data according to a predicate. More...
 
struct  IdentityCore< IT >
 A neutral identity-function core, also serving as point-of reference how any core is intended to work. More...
 
class  IterTool< CORE >
 Standard functionality to build up any iterator tool. More...
 
class  SingleValCore< VAL >
 Implementation of a singleton value holder, which discards the contained value once "iterated". More...
 
class  SingleValIter< VAL >
 Pseudo-Iterator to yield just a single value. More...
 
class  SkipRepetition< VAL >
 Helper: predicate returning true whenever the argument value changes during a sequence of invocations. More...
 
class  TransformingCore< IT, VAL >
 Implementation of custom processing logic. More...
 
class  TransformIter< IT, VAL >
 Iterator tool treating pulled data by a custom transformation (function) More...
 

Functions

template<class IT , class CON >
void append_all (IT iter, CON &container)
 
template<class IT , typename PRED >
auto filterIterator (IT const &src, PRED filterPredicate)
 Build a FilterIter: convenience free function shortcut, picking up the involved types automatically. More...
 
template<class IT , typename PRED >
auto filterIterator (IT &&src, PRED filterPredicate)
 
template<class IT >
auto filterRepetitions (IT const &source)
 filters away repeated values emitted by source iterator
 
template<class IT >
auto filterRepetitions (IT &&source)
 
template<class VAL >
auto nilIterator ()
 not-anything-at-all iterator
 
template<class CX >
bool operator!= (IterTool< CX > const &ito1, IterTool< CX > const &ito2)
 
template<class CX >
bool operator== (IterTool< CX > const &it1, IterTool< CX > const &it2)
 
template<class IT >
IT::value_type pull_last (IT iter)
 
template<class VAL >
auto singleValIterator (VAL &&something)
 Build a SingleValIter: convenience free function shortcut, to pick up just any value and wrap it as Lumiera Forward Iterator. More...
 
template<class IT , typename FUN >
auto transformIterator (IT const &src, FUN processingFunc)
 Build a TransformIter: convenience free function shortcut, picking up the involved types automatically. More...
 
template<class IT , typename FUN >
auto transformIterator (IT &&src, FUN processingFunc)
 

Namespaces

 lib
 Implementation namespace for support and library code.