[Dune] Reverse iterators in FieldVector

Markus Blatt Markus.Blatt at iwr.uni-heidelberg.de
Thu Nov 26 18:51:43 CET 2009


On Thu, Nov 26, 2009 at 06:12:12PM +0100, Oliver Sander wrote:
> Dear Dune!
> When working on FS 438 I found the following behavior of FieldVector:
> The method rbegin() returns a bidirectional iterator to the last element
> of the vector.  To get to the second-to-last element you can call 
> operator--.
> However, the standard stl behavior is to return a reverse iterator which
> needs to have operator++ called to get to the second-to-last element.
> 
> Is this nonstandard behavior intended or is it a bug that needs fixing?
> 


It is intended and all algorithms honour and rely on this behaviour.

Changing this would be a lot of unnecessary work. Besides, the
implementation of all stl containers  is a wrapper of the forward
iterator that changes its bahaviour. This is made in way that
dereferencing a reverse iterator creates a temporary copy of the
underlying forward iterator, calls operator--
on it and dereferences it.

Of course, without measurements I cannot guarantee that this is really
slower than our implementation, but I am tempted to assume, that it
is. (Maybe 7%? ;)

BTW: The current behaviour prohibits FieldVector to be a descendant of
std::array without modifying the std behaviour. (I am sorry for not
noticing this earlier, but it just was not on my mind).

Cheers,

Markus




More information about the Dune mailing list