Skip to content
Snippets Groups Projects
Commit a6bfcb25 authored by Carsten Gräser's avatar Carsten Gräser
Browse files

[!781] Allow iterator based transformations in TransformedRangeView

Merge branch 'feature/extend-transformedrangeview' into 'master'

ref:core/dune-common\> 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.

See merge request [core/dune-common!781]

  [core/dune-common!781]: gitlab.dune-project.org/core/dune-common/merge_requests/781
parents bccda895 7a9fef64
1 merge request!781Allow iterator based transformations in TransformedRangeView
Pipeline #28102 passed
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment