TickDuration.to's second template parameter
Steven Schveighoffer
schveiguy at yahoo.com
Mon Apr 9 06:36:45 PDT 2012
On Sat, 07 Apr 2012 20:03:25 -0400, Jonathan M Davis <jmdavisProg at gmx.com>
wrote:
> 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.
I think what Andrei is asking for is to change this:
T to(string units, T)() @safe const pure nothrow
Into this:
T to(string units, T = long)() @safe const pure nothrow
Which I don't think will hurt anything.
An additional annoyance that I would think is solved is you always have to
include the parentheses. i.e.:
td.to!"msecs"()
vs.
td.to!("msecs", long)();
-Steve
More information about the Digitalmars-d
mailing list