Boost logo

Boost Users :

From: pbristow_at_[hidden]
Date: 2019-07-12 08:01:26


> -----Original Message-----
> From: Boost-users <boost-users-bounces_at_[hidden]> On Behalf Of Dan
> Bloomquist via Boost-users
> Sent: 11 July 2019 17:50
> To: Bill Moo <mookimoo73_at_[hidden]>; boost-users_at_[hidden]
> Cc: Dan Bloomquist <boost_at_[hidden]>
> Subject: Re: [Boost-users] A question regarding gregorian week_iterator
>
> 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.

That is a surprise to me (and Bill too I suspect 😉).

I think this should be prominently mentioned in the documentation.

Paul

Paul A. Bristow
Prizet Farmhouse
Kendal, Cumbria
LA8 8AB UK


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