Bug 9214 – TickDuration.to should probably be a property
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-26T17:51:00Z
Last change time
2012-12-27T20:45:19Z
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2012-12-26T17:51:54Z
Example from datetime:
import std.datetime;
import std.stdio;
import std.conv;
void main()
{
int a;
void f0() {}
void f1() {auto b = a;}
void f2() {auto b = to!(string)(a);}
auto r = benchmark!(f0, f1, f2)(10_000_000);
writefln("Milliseconds to call fun[0] n times: %s", r[0].to!("msecs", int));
}
2.060: test.d(12): Error: not a property r[cast(uint)0].to
If we want to preserve this syntax we have to make the `to` function a property. Or we can change the code sample.. but I kind of like the way it's written.
Comment #1 by issues.dlang — 2012-12-26T21:43:00Z
to makes no sense as a property. It's a conversion function, not an abstraction for a variable. If anything, the example needs to be changed.
Now, there's a decent chance that with what a lot of people think about UFCS and templated functions that using to without the parens for the function call won't be necessary long term, but if it's a property, then it'll likely be required to not have the parens long term, and given that to is a conversion function, I really don't think that makes sense. If you want a property, then use one of the property functions which wrap to (msecs, seconds, etc.).
I think that I'll just create a commit which changes the example to use the property function instead of to, since that's cleaner anyway.