[hybrid] Allow dune-istl MultiBlock types as ranges in forEach
Currently MultiTypeBlockMatrix can be used as a range in forEach
using namespace Dune::Hybrid;
forEach(m, [](auto& row){
...
});
because it has a static constexpr member function size
. However, size
is deprecated in favour of N
.
This MR attempt at removing the deprecation warning (because N
is looked for first) and also allow types that use a static constexpr member function N
to be interpreted as range
in the sense of Hybrid::forEach
.
Merge request reports
Activity
Are you sure about the meaning of
size()
for matrices to be the number of rows? In many libraries matrix-size is number of rows times number of columns. What, if you have column-major ordering?I would suggest a slightly different design, e.g.
using namespace Dune::Hybrid; MultiTypeBlockMatrix<...> m(...); forEach(rows(m), [](auto& row){ ... });
or
m.rows()
, or if you just want to have traversal of the major-dimension:m.asTuple()
. The specialization ofsize()
for tuples does not kick in, since the matrix is just derived from tuple, but not the tuple type itself. So, one could also just add a specialization ofstd::tuple_size
for multi-type matrices instead.While it's slightly inconvenient I'd not like to have a specialization for
::N()
here. Whilesize()
has a generic meaning (motivated by the STL) this is not the case for::N()
.forEach
is for iterating over ranges and extends the range concept to statically sized multi-type ranges usingstatic constexpr size()
. If your class does not providesize()
, then it's neither a container nor a range in the classical or extended sense.This also applies to
MultiTypeBlockMatrix
. Unfortunately, I somehow missed the deprecation ofsize()
. In fact I think it's a pretty bad idea, especially because it's replaced by a one-letter method whose introduction was a bad idea, too.I like @simon.praetorius' suggestion to provide ranges using
rows(matrix)
.mentioned in merge request dune-istl!424 (merged)
There is a proposal now in dune-istl: dune-istl!425