(git HEAD) std.datetime spewing deprecation messages

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 5 12:00:39 PDT 2014


On Thu, 5 Jun 2014 14:35:16 +0000 (UTC)
Byron Heads via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> On Thu, 05 Jun 2014 07:18:59 -0700, H. S. Teoh via Digitalmars-d
> wrote:
>
> > On Thu, Jun 05, 2014 at 01:23:47AM -0700, Jonathan M Davis via
> > Digitalmars-d wrote:
> >>
> >> {
> >>     auto d = dur!"days"(12) + dur!"minutes"(7) +
> >> dur!"usecs"(501223); long days;
> >>     int seconds;
> >>     short msecs;
> >>     d.split!("days", "seconds", "msecs")(&days, &seconds, &msecs);
> >>     assert(days == 12);
> >>     assert(seconds == 7 * 60);
> >>     assert(msecs == 501);
> > [...]
> >
> > Very nice! I like this. It looks very D-ish, and very idiomatic.
>
> if only we could avoid the quotes, would a enum array work?
> d.split![days, second, msecs](...)

It's a common idiom in core.time and std.datetime to use strings to represent
units when you need to give the units as template arguments. If it hade't been
strings, it would have been an enum (otherwise, they would risk conflicting
with local variables and whatnot), in which case it would have been even more
verbose - e.g. Units.days, Unit.seconds, Unit.msecs (and IIRC, I originally
had something like that until Anrei suggested that I use strings in the
original review for std.datetime). Also, days, seconds, and msecs are free
functions in core.time which forward to dur!"days", dur!"seconds", and
dur!"msecs", so trying to use them on their own would try and use those free
functions, which obviously isn't what we want at all. I can see why you might
want to remove the quotes, but they really aren't that bad, and using strings
for this purpose has turned out to be extremely useful and flexible.

- Jonathn M Davis


More information about the Digitalmars-d mailing list