|
Boost : |
Subject: Re: [boost] [chrono/date] Unit specifiers arithmetic
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2013-05-07 07:53:07
2013/5/6 Vicente J. Botet Escriba <vicente.botet_at_[hidden]>
> Hi,
>
> Moving from checked dates to unchecked ones by default and forcing to user
> the Unit specifiers year/month/day in any date constructor (even the
> unchecked ones) has some ugly consequences. Note that I was able to build
> an unchecked date as
>
> date d(2013,5,6, no_check);
>
> Given
>
> year y;
> month m;
> day d;
>
> the following will not compile now as the constructors expects a year but
> y+1 is an int.
>
> date d(y+1, m, d);
>
> The user needs to type
>
> date d(year(y+1), m, d);
>
> Is this what we want to provide to the user or should we add basic
> arithmetic on these unit specifiers?
>
> Best,
> Vicente
>
I suggest pointer-like arithmetic on the types. I.e. for year:
year +- int -> year
int + year -> year
year - year -> int
year + year -- not allowed
The above seems intuitive to me.
And to avoid unexpected situations I suggest disabling the implicit
conversions: year <-> int
I think any built-in integer makes sense instead of int here.
Regards,
Kris
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk