[yasp] Use the ReservedVector begin() and end() directly
Summary
In YaspGrid
the level iterators YGridLevelIterator
are just aliases of ReservedVector::const_iterator
. Those should be constructed directly from ReservedVector::begin()
and ReservedVector::end()
(plus maybe a shift - should be a random access iterator) and not my manually constructing the GenericIterator
wrapper as it is currently done. Changing the implementation detail in dune-common, see dune-common!1158 (merged) then leads to errors in dune-grid. This MR fixes this situation.
The second issue is the wrong usage of that iterator. The expressions ++grid.begin()
is not guaranteed to compile. And indeed, changing the iterator implementation slightly in ReservedVector
leads to a compiler error. The issue is also documented in https://en.cppreference.com/w/cpp/iterator/next#Notes
The third issue corrected in this MR is the default-initialization of iterators: See https://stackoverflow.com/questions/3395180/what-is-an-iterators-default-value, In general default initialization (not value-initialization) is undefined behavior, the iterator is not bound to any container any any operation with it might lead to undefined behavior, even comparison with another default initialized iterator. For example, an iterator might be a raw pointer, default initializing a pointer means not initializing it at all. Comparing uninitialized pointers is UB. Instead, iterators are value-initialized like Iter iter = {}
leading to a null initialization for pointers, for example.