Hello everyone,
I was wondering, while looking at the source files, why the
date_iterator doesn't provide an operator--() ???
I've added this in the "date_iterator.hpp" file :
//---------------------------------------------------------
date_itr_base& operator--()
{
current_ = current_ - get_offset(current_);
return *this;
}
//---------------------------------------------------------
I've rebuilt the library and done this little test :
//---------------------------------------------------------
#include <iostream>
#include
Hi Luc -
I was wondering, while looking at the source files, why the date_iterator doesn't provide an operator--() ???
A couple reasons. 1) I wasn't sure it would be needed, so to keep things simple I left it out. 2) See below...
I've added this in the "date_iterator.hpp" file :
//--------------------------------------------------------- date_itr_base& operator--() { current_ = current_ - get_offset(current_); return *this; } //---------------------------------------------------------
I've rebuilt the library and done this little test :
//--------------------------------------------------------- #include <iostream> #include
int main(void) { using namespace boost::gregorian;
date today = day_clock::local_day(); day_iterator ditr(today, 1); int nbDaysToIterate = 360;
for (;nbDaysToIterate != 0; --ditr, --nbDaysToIterate) { std::cout << to_iso_extended_string(*ditr) << std::endl; } } //---------------------------------------------------------
Everything seems to run OK. I've checked the february month and it has a 28th... Now I wonder why wasn't it included in the release ???
It's true that this works fine for the day_iterator. If you try the same test with the month and year iterators, they will fail. The reason being that the functors that calculate 'add a month' and 'add a year' are written assuming a forward iterator. That's not to say that they couldn't be modified to support bi-directional iteration, just that it is a tad harder in these cases. Jeff
participants (2)
-
Jeff Garland
-
Luc Bergeron