Boost logo

Boost Users :

Subject: Re: [Boost-users] [Filesystem] Reverse traversal of boost::filesystem::path::const_iterator?
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-11-02 17:01:10


> To be clear about my question, let me pose it as a syllogism, where
> 'container' is an instance of SomeContainer:
>
> 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?

I'm not a language lawyer, but I'll point out that at least boost::reverse_iterator [1]
seems to assume this (I don't see how it could be implemented otherwise).

(Not so) incidentally, boost::reverse_iterator seems like an appropriate solution
to your original problem of iterating over a path in reverse :)

Regards,
Nate

[1] http://www.boost.org/doc/libs/1_51_0/libs/iterator/doc/reverse_iterator.html
                                               



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