I added the missing * in the line above.
If your "last" variable really is the last entry and not the end()
value then it won't call the do_something() method for the last one.
The algorithm does not call do_something when first == last. That's
fundamental. And it's the right behavior when you call an algorithm with
a pair of iterators from a container, whether that pair is obtained by
calling begin() and end() or by calling rbegin() and rend().
I
think possibly the naming was wrong with thes methods since begin()
really does return the beginning position of the list (if there is one)
but end() does not return the end position, it returns a value that
signifies you've already gone past the final valid position,
They return iterators that mark the beginning and the end of the
sequence that's managed by the container. Again: a sequence is
designated by a pair of iterators. The first iterator points to the
first element in the sequence and the second iteraotr points past the
end of the sequence. It doesn't matter where the sequence comes from:
that's what they have to be.
which is
not the same thing at all. Its the difference between fgetc() returning
the final character in a file and returning EOF.
Not really. begin() and end() [and rbegin() and rend()] return
iterators. To check whether you're at the end of a sequence you compare
the iterators for equality.
I don't see why , so long as the begin() and end() methods are
consistent within the iterator type.
Iterator types do not have begin() and end() methods, so I don't know
what you're trying to say here.
The reason that rbegin() and rend() hold the iterator that points to the
element that precedes the element that they point at is simply that
rend() can't be implemented any other way. Using vector, for example,
you can't have an iterator that points to the element before the first
element in the contained array. So rend() creates an iterator that
points to the first element.
--
-- Pete
Roundhouse Consulting, Ltd. (
www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (
www.petebecker.com/tr1book)