Boost logo

Boost Users :

Subject: Re: [Boost-users] [Filesystem] Reverse traversal of boost::filesystem::path::const_iterator?
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2012-11-02 12:06:49


Hi Nat,

On Fri, Nov 2, 2012 at 9:22 AM, Nat Linden <nat_at_[hidden]> wrote:
> IF SomeContainer::end() is documented to return a bidirectional iterator,
> AND container.end() != container.begin(),
> THEN the following code is valid, and references the last item in container:
>
> SomeContainer::const_iterator it = container.end();
> --it;
> SomeContainer::value_type const& last = *it;
>
> Always true?

It isn't really clear to me by me reading of the standard (well,
n3126). On the one hand, in 24.2.6, the pre/post conditions are:

pre: there exists s such that
r == ++s.
post: r is dereferenceable.
--(++r) == r.
--r == --s implies r == s.
&r == &--r.

Given that s references the last element, and r is the past-the-end
iterator, then it would imply that your syllogism is true.

Of course, a previous section (24.2.1.5) talks about the possibility
of singular iterators and default constructable iterators. I've never
seen such things in the context of a bidirectional iterator.

Of course, having now quoted the standard, this is when someone that
really knows what they're talking about comes and corrects me. ;)

HTH,
Nate


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net