TickDuration.to's second template parameter
Jonathan M Davis
jmdavisProg at gmx.com
Mon Apr 9 10:05:09 PDT 2012
On Monday, April 09, 2012 09:36:45 Steven Schveighoffer wrote:
> 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)();
We could add that, but why? td.msecs already does what td.to!"msecs"() would
do if to defaulted to long. I don't see any reason to use to directly unless
you're using something other than long. And if you use a type of than long,
you're going to have to provide the whole thing anyway - e.g. td.to!("msecs",
uint)().
- Jonathan M Davis
More information about the Digitalmars-d
mailing list