TickDuration.to's second template parameter
Jonathan M Davis
jmdavisProg at gmx.com
Sat Apr 7 21:09:34 PDT 2012
On Saturday, April 07, 2012 15:59:57 Andrei Alexandrescu wrote:
> Whenever I use TickDuration.to, I need to add the pesky second argument,
> e.g. TickDuration.to!("nsecs", uint). Would a default make sense there?
>
> Also, double doesn't work, although I sometimes could use that.
>
>
> Thoughts? Destroyers?
That's odd. I was sure that I responded to this earlier, but my post seems to
have disappeared. So, I'll try again.
TickDuration has the seconds, msecs, usecs, and nsecs functions which
effectively gives you to with a default of long for each of the units supported
by TickDuration. So, that's the closest that it has to default arguments. I
don't think that it would really make sense to give to default arguments to to
on top of that. So, if you really want uint rather than long, you'd do either
auto value = td.to!("nsecs", uint)();
or
auto value = cast(uint)td.nsecs;
As for double, it should work. SHOO had had functions similar to seconds,
msecs, usecs, and nsecs which defaulted to real, but I removed them a while
back, because it made it too confusing to keep them all straight. But to
should work with integral values with a size of at least 4 bytes as well as
all floating point types. The unit tests do test real, but they don't test
double at all. So, it's possible that there's a bug which prevents it from
working, but both float and double should work. If they don't, it's a bug which
needs to be reported and fixed.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list