Ah! of course, that makes perfect sense to me now, so I am wiser now
than I was when I posted so thanks again Dan.
--
Bill
On Thu, 11 Jul 2019 at 17:50, Dan Bloomquist
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.