TickDuration.to's second template parameter
Jonathan M Davis
jmdavisProg at gmx.com
Sat Apr 7 17:03:25 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?
Well TickDuration.nsecs is a wrapper for TickDuration.to!("nsecs", long"),
TickDuration.msecs is a wrapper for TickDuration.to!("msecs, long"), etc. So,
that's basically how defaults were added. I question that it makes sense to
add defaults to the to function itself - though having long chosen as the
default doesn't really help you, since you'll either have to be explicit like
you have been or cast using the default version.
auto value = td.to!("nsecs", uint)();
or
auto value = cast(uint)td.nsecs;
> Also, double doesn't work, although I sometimes could use that.
As for double not working, that sounds like a bug. It uses
__traits(isFloating, T) if the type isn't an integral type and therefore
should work with floating point values. IIRC, SHOO originally had some other
wrapper functions for defaulting to real, which I removed because it made it
too confusing to keep the long vs real functions straight, but double and real
should still work. It _does_ look like real is used with it in some of the
unit tests, but I don't think double is. If it doesn't work though, that
sounds like a bug (either in dmd or druntime, depending on why it doesn't
work).
- Jonathan M Davis
More information about the Digitalmars-d
mailing list