176 | | |
| 176 | == Boost.Accumulators == |
| 177 | == Dependents accumulators == |
| 178 | |
| 179 | The accumulator library allows to determine dependency between accumulator, but not between accumulator_sets. |
| 180 | I would like to define an accumulator_set c so when we cumulate in two others c1 and c2 accumulator_sets we cumulate also in c, some thing like: |
| 181 | {{{ |
| 182 | #!cpp |
| 183 | typedef dependable_accumulator_set <double, ...> dependable_acc_type; |
| 184 | |
| 185 | dependable_acc_type c1, c2; |
| 186 | dependable_acc_type c=c1+c2 |
| 187 | |
| 188 | dependable_acc_type c3; |
| 189 | |
| 190 | c+=c3; |
| 191 | |
| 192 | c1(1); |
| 193 | c2(1); |
| 194 | c3(2); |
| 195 | assert(count(c)==3); |
| 196 | assert(sum(c)==4); |
| 197 | }}} |
| 198 | How dependable_accumulator_set can be defined? Here follows the interfaces of such a class and the pseudo code, I've named the class dependable_accumulator_set, sorry but I have not found a shorter and better name (may be observed/listened?) |
| 199 | {{{ |
| 200 | #!cpp |
| 201 | template <typename T, typename F, typename W> |
| 202 | class dependable_accumulator_set : public acumulator_set<T,F,W> |
| 203 | { |
| 204 | public: |
| 205 | dependable_accumulator_set(); |
| 206 | void add_dependent(dependable_acumulator_set&); |
| 207 | void remove_dependent(dependable_acumulator_set&); |
| 208 | |
| 209 | template<typename A1> |
| 210 | void operator ()(A1 const &a1) { |
| 211 | for (acc in dependents) { |
| 212 | acc(a1); |
| 213 | } |
| 214 | this->accumulator_set_type::operator()(a1); |
| 215 | } |
| 216 | dependable_accumulator_set<T,F,W>& operator+=(dependable_accumulator_set<T,F,W>); |
| 217 | dependable_accumulator_set<T,F,W>& operator-=(dependable_accumulator_set<T,F,W>); |
| 218 | }; |
| 219 | |
| 220 | template <typename T, typename F, typename W> |
| 221 | dependable_accumulator_set<T,F,W> |
| 222 | operator+()(dependable_accumulator_set<T,F,W>,dependable_accumulator_set<T,F,W>); |
| 223 | }}} |
| 224 | |
| 225 | Another variant could be also to have a temporary accumulator that cyclically push its current value on another accumulator. |
| 226 | |
| 227 | It will also interesting to have a dependable and cyclic accumulator set. It would be great to integrate these features on a unique class (accumulator_set?) in a clean way. |
| 228 | {{{ |
| 229 | #!cpp |
| 230 | template <typename T, typename F, typename W, |
| 231 | typename DependablePolicy, |
| 232 | typename CyclicPolicy> |
| 233 | class accumulator_set; |
| 234 | }}} |
| 235 | |
| 236 | |