Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2003-08-12 06:47:56


On Tue, 12 Aug 2003 10:44:45 +1000, Chris Trengove wrote
> The date iterators in Boost Date-Time appear to be designed to
> support iteration forward in time, being modelled on the STL
> InputIterator. However, at times it is convenient to iterate
> backwards in time, and the temptation is just to use something like
>
> day_iterator ditr(date,-1);
> ++ditr;
>
> that is; specify a negative "offset" as the optional construction parameter
> which all four of the iterators provide.

Yep. This has come up several times before...

> This works for all of the provided iterators except the
> month_iterator, and it wouldn't be too difficult to make that one
> work as well (by providing a subtract() method for the wrapping_int2
> template used in the implementation).

Another user has submitted a change to me, that hasn't made it into
the library, that performs the equivalent by modifying adjust_functors.hpp.
Looking back on the history of the number of requests on this it looks like
it should be a priority to officially support this option. Or perhaps, even
better, to step up and support bi-directional or random access iterators.

> Are there any other issues involved in providing this support for backwards
> iteration?

No, it appears not, but if you do this make sure to write some tests to be sure...

Jeff


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk