Reference semantics in VariableBlockVector
When "copying" a block from a VariableBlockVector
, one has reference semantics due to Dune::Imp::BlockVectorWindow
being used as return type of the operator[]
:
using Vector = Dune::VariableBlockVector<...>;
Vector v(n);
// ... set up v
auto supposed_block_copy = v[0];
supposed_block_copy= foo(); // this also changes v!
I find this a little surprising, if not dangerous, because it's different from e.g. copying a block from a simple BlockVector
. In my opinion, this should be made more explicit in the documentation.
Alternatively, I thought of a window implementation that can manage it's own data (e.g. via a unique_ptr
) if someone tries to copy construct from it.