On the cppreference page of reverse_iterator I find the following remark
std::reverse_iterator
does not work with iterators that return a reference to a member object (so-called "stashing iterators"). An example of stashing iterator isstd::filesystem::path::iterator
.
Is that claim correct? And, if yes, why is that?
To me the restriction makes no sense, as I would assume that the reverse iterator basically swaps the operator ++
and operator --
(and stores the underlying iterator off by one).
EDIT: Apparently the question can be mis-understood:
I understand that we need the decrement operation once to implement a reverse iterator. The question is why this is not implemented during construction of the reverse_iterator
. Then the problem with the stashing iterator is avoided. But apparently this is not how it is done, and the decrement is done every time the iterator is dereferenced. Why?