template<class SRC, typename AGG, class GRP>
class lib::iter_explorer::GroupAggregator< SRC, AGG, GRP >
Decorator for IterExplorer to group consecutive elements controlled by some grouping value GRP and compute an aggregate value AGG for each such group as iterator yield. The first group is consumed eagerly, each further group on iteration; thus when the aggregate for the last group appears as result, the source iterator has already been exhausted. The aggregate is default-initialised at start of each group and then the computation functor FAGG is invoked for each consecutive element marked with the same grouping value — and this grouping value itself is obtained by invoking the functor FGRP on each source value. All computation are performed on-the-fly. No capturing or reordering of the source elements takes place, rather groups are formed based on the changes of the grouping value over the source iterator's result sequence.
- Template Parameters
-
AGG | data type to collect the aggregate; must be default constructible and assignable |
GRP | value type to indicate a group |
- Note
- while
groupFun
is adapted, the aggFun
is not adapted to the source iterator, but expected always to take the value type of the preceding iterator, i.e. *srcIter
. This limitation was deemed acceptable (adapting a function with several arguments would require quite some nasty technicalities). The first argument of this aggFun
refers to the accumulator by value, and thereby also implicitly defines the aggregate result type.
- Warning
- the Aggregator AGG must not capture references to upstream internal state, because the overall pipeline will be moved into final location after the initial ctor call.
Definition at line 1025 of file iter-explorer.hpp.