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

Allow iterator based transformations in TransformedRangeView

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

```cpp
template<class Range>
auto sparseRange(Range&& range) {
  return Dune::iteratorTransformedRangeView(std::forward<Range>(range), [](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:

* `TransformedRangeView` has a new template parameter for selecting
  value- or iterator-based transformation. Value-based is default.
* A new helper function `iteratorTransformedRangeView()` allows
  to generate iterator based transformations.
parent d5af0301
No related branches found
No related tags found
1 merge request!781Allow iterator based transformations in TransformedRangeView
Pipeline #27957 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