Boost logo

Boost Users :

From: Dan Bloomquist (boost_at_[hidden])
Date: 2019-07-11 16:50:15


Bill Moo wrote:
> Thank you for the reply Dan.
>
> Changing the iteration logic does indeed stop when expected, but for
> me it raises a couple of question.
>
> When using the month_iterator the != approach works so why not for the
> week_iterator? As the month_iterator option I have uses the same
> date_period approach.

The functor for incriminating by week simply adds 7 to the day count and
365 % 7 != 0. For the month iterator it digs down to find the actual
calendar spans for the year and month given. The 'day' of each iteration
by month lands on the same day of the month. It will work for leap years.

 Â Â Â Â Â  for (boost::gregorian::month_iterator mi = dp.begin(); mi <
dp.end(); ++mi) {
 Â Â Â      std::cout << mi->month() << " " << mi->day() << std::endl;
 Â Â Â  }

For boost::gregorian iterators, I would only use the '<' rather than
'!=' to insure you don't miss a hit.

>
> The second question is since the iteration is over a predefined date
> range whose start and ends are set why didn’t the iterations exhaust
> on say Aug 2019? What allowed it to continue way outside of the
> constrained range implying that the range is in fact much larger.

These are not container iterators. The iterator is valid throughout the
calendar range, they are only a day position in the calendar. Much like
a char* can point anywhere in memory yet char* can be treated like an
iterator. There is no specialization to 'contain' the iterator.
Best, Dan.


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