Skip to content
Snippets Groups Projects
user avatar
Carsten Gräser authored
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.
7a9fef64
History
Name Last commit Last update