Skip to content

Allow iterator based transformations in TransformedRangeView

Carsten Gräser requested to merge feature/extend-transformedrangeview into master

This extends TransformedRangeView by also allowing to apply a transformation to the iterator directly. While the (existing) default mechanism is to use f(*it) where f is the transformation and it an iterator of the wrapped range, the new iterator based transformation uses f(it) instead. This allows to incorporate additional information from the iterator in the transformation.

Using the new functionality one can e.g. easily implement structured bindings support for sparse ranges using

template<class Range>
auto sparseRange(Range&& range) {
  return Dune::transformedRangeView(std::forward<Range>(range), Dune::taggedCallback<Dune::IteratorTransformationTag>([](auto&& it) {
      return std::tuple<decltype(*it), decltype(it.index())>(*it, it.index());
  }));
}

...

for(auto&& [entry,col] :  sparseRange(matrix[row]))
  y[row] += entry*x[col];

Some more implementation details:

  • This adds the TaggedCallback<Tag,F> helper class and the corresponding generator function taggedCallback<Tag>(f) for tagging a callback. Using this mechanism we can provide additional information on the callback.
  • If the TransformedRangeView is provided with a callback of type TaggedCallback<IteratorTransformation,F>, then it iterator based transformation is used.

Merge request reports

Loading