Boost logo

Boost Users :

From: Jeff Garland (jeff_at_[hidden])
Date: 2007-02-12 15:23:21


Steve Johns wrote:
> Getting started with Boost::Date_Time ...
>
> It seems that this is OK:
>
> greg_year y1(2000);
> y1 = y1 + 1;
>
> but this is not:
>
> greg_year y1(2000);
> y1++;
>
> I take it that the increment and decrement operators are not implemented for
> greg_year (or the corresponding month, day, etc. types).

Right.

> Is this just incidental to the current implmentation, or is there some
> particular architectural or domain reason why ++ and -- aren't in the mix?

Most users don't use greg_year much so it's never really come up. That said,
there would be some issues. We'd need to specify this for greg_month to be
symmetric. So what would we do with this:

greg_month m(12);
m++; //wrap?
greg_year y(9999); //max year
y++; //exception I would guess?

So, the bottom line is that these ops aren't supported to try and keep the
interface smaller. And, in general, increment and decrement require a large
amount of context that isn't necessarily obvious it was a good idea. BTW, are
aware that you can do this?

date d(....);
years y(1);
y += years(2);
d += y;
d += week(20);

Jeff


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