
On May 11, 2013, at 5:54 AM, Roland Bock
On 2013-05-08 18:08, Vicente J. Botet Escriba wrote:
as the conversion between concrete dates could be expensive I guess that these conversion must be explicit.
But this has some consequences when used the implicit conversion was hidden a not efficient implementation, e.g.
date ISO_week_start = mon <= jan/day(4)/y;
jan/day(4)/y should be ymd_date as is the efficient representation.
The date generator was declared as
date operator<=(weekday wd, date x);
Do you really want to allow/document/support/advocate the American date format in C++? Why not restrict the format to something close to ISO date format for ISO C++?
If the types are unambiguous, such as with day, month, and year types, then any order can be supported. Those comfortable with a non-ISO order can do what they prefer with type safety.
That way you could introduce a new type, say ym_type and
ym_type operator/(year y, month m); date operator/(ym_type ym, day d);
Neither explicit nor implicit conversion necessary :-)
You misunderstood the conversion context. There are several formats in contemplation: serial, days since an epoch; ymd; day of year; week of year; etc. conversions among them are sometimes costly, so the notion is to make them explicit.
Another question I have about this is: Is is really a good idea to use operator/()? It does prevent you from calculating ratios between periods, e.g.
int ratio = year(3)/month(4); // ratio = 9
I've thought that using the operator was a little too cute, but this is an interesting argument against it.
I'd therefore prefer another operator, e.g. operator <<
-1 That operator is for I/O, even if unsupported. (Someone might want to add I/O, even if not standardized.)
But to be completely honest: I don't see the benefit of constructing dates this way. Why not simply use a constructor?
date(year, month, day);
The issue is that there are other argument lists to support, so the combinations get complicated. We're exploring lots of options.
With C++11 you could then write:
date ISO_week_start = mon <= { y, jan, day(4) };
Using an initializer list is yet another option to consider. ___ Rob (Sent from my portable computation engine)