Lumiera  0.pre.03
»edit your freedom«
GroupAggregator< SRC, AGG, GRP > Class Template Reference

#include "lib/iter-explorer.hpp"

Description

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
AGGdata type to collect the aggregate; must be default constructible and assignable
GRPvalue 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.

Definition at line 996 of file iter-explorer.hpp.

Public Types

using pointer = typename meta::RefTraits< AGG >::Pointer
 
using reference = typename meta::RefTraits< AGG >::Reference
 
using value_type = typename meta::RefTraits< AGG >::Value
 

Public Member Functions

template<class FGRP , class FAGG >
 GroupAggregator (SRC &&dataSrc, FGRP &&groupFun, FAGG &&aggFun)
 
bool checkPoint () const
 
void iterNext ()
 
reference yield () const
 

Protected Types

using Aggregator = function< void(AGG &, SrcValue &)>
 
using Grouping = function< GRP(SRC &)>
 
using SrcValue = typename meta::ValueTypeBinding< SRC >::value_type
 

Protected Member Functions

void pullGroup ()
 
SRC & srcIter () const
 

Protected Attributes

std::optional< AGG > agg_ {}
 
Aggregator aggregate_
 
Grouping grouping_
 

Member Function Documentation

◆ pullGroup()

void pullGroup ( )
inlineprotected
Note
establishes the invariant: source has been consumed up to the beginning of next group

Definition at line 1062 of file iter-explorer.hpp.

+ Inheritance diagram for GroupAggregator< SRC, AGG, GRP >:
+ Collaboration diagram for GroupAggregator< SRC, AGG, GRP >:

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