annoying problem I encountered is that date iterators conform to InputIterator model, rather then Random Access Iterator.
The reason for this is that it is unclear in all cases that an operation is easily reversed. In particular, the problem comes about with handling the end of the month. Say for example you start an iterator on Jan 30. When you iterate to February what happens? Well the rule the supplied iterator is to back up to the end of the February -- either the 27 or 28th for a leap year. Yes, I understand these complications. I was quite surprised, btw,
--- In Boost-Users@yahoogroups.com, "Jeff Garland"
Given that these rules are complex and at least possibly non-reversible I tried to limit the exposure of the iterator: hence input iterator. In retrospect, however, it could probably be RandomAccess because I can't give you an actual case where making the iterator reverse is an actual issue. I can live with InputIterator, but having RandomAccess (or, at least, Bidirectional) will simplify life significantly. Is there any chance you will consider this feature request for future development?
If you want to use the iterator you can simply do the following:
month_iterator mi(d, 3); // configure iterator to add 3 months at a time. mi++; //adds 3 months. This is nice, thanks for pointing out this feature.
If you don't want to use the iterator there are a couple of possible solutions. One is to do the following: int N = 3; //add 3 months date d(...);// constructed however date d1(d.year(), d.month()+N, d.day()); Well, except that this doesn't handle year wrap arounds and other the issues associated with the end of the month as described above. So you have to write some supporting code to handle That is exactly what I did as a temporary solution. I hope though, that someday you will create more powerful iterator or some other means to accomplish this task in simpler and cleaner way.
So bottom line for this problem is: I was wrong talking about inefficiency -- there is a way to move few month at a time. The real problem though that I can't move iterator backward. One more thing: it is quite inconvinient that it is prohibited to create a vector of dates. Do you have plans to make it vector compliant? Default constructor could initialize it to not_a_date for instance. Another little issue: there are few typos on the boost web site. Example "Print a month" looks garbled (probably transformation from source code to html failed). For instance: int std::cin >> year; and int eom_day = gregorian_calendar::end_of_month_day( date endOfMonth(year,month,eom_day); look odd. Don't know about other examples; did not have chance to study them carefully. Also under "Build & Compiler information" there is a typo: /boost/date_time/gregoran -- gregorian calendar system header files should be /boost/date_time/gregorIan Best regards, Kirill Lapshin.