I'm trying to come up with an idomatic way of writing this
boost::gregorian::month_iterator start(boost::gregorian::date(1901,1,1),1);
boost::gregorian::date end(2000,12,31);
int i = 0;
while(start <= end) {
boost::gregorian::gregorian_calendar::day_of_week_type x = (*start).day_of_week();
if(x==0)
++i;
}
This is fine, but I wondered if there was a way of writing it like
boost::gregorian::month_iterator start(boost::gregorian::date(1901,1,1),1);
boost::gregorian::month_iterator end(boost::gregorian::date(2000,12,31));
const int i = std::count_if(start,end,[](boost::gregorian::month_iterator& start) {
boost::gregorian::gregorian_calendar::day_of_week_type x = (*start).day_of_week();
return (x==0);
});
Same result, but I think it's prettier code, it's more like a functional approach (which I like) and the intention of what I'm trying to achieve is clearer. I have a feeling I have to use any_range<> but I'm not really sure how in this case as the month_iterator doesn't seem to have all the normal semantics of forward iterators