Code snippet: import core.time: TickDuration; import std.datetime: StopWatch, AutoStart; void main() { auto wait = TickDuration.from!`msecs`(1000); auto timer = StopWatch(AutoStart.yes); while (timer.peek < wait) // Okay. { } while (wait >= timer.peek) // Compile error. { } } Compiler output: comparison.d(13): Error: function core.time.TickDuration.opCmp (ref const(TickDuration) rhs) const is not callable using argument types (TickDuration) comparison.d(13): Error: timer.peek() is not an lvalue I assume the same thing happens elsewhere in the library. As D strives to be an intuitive language, I reason this to be a bug. "<" and ">=" should work identically in this circumstance.
What's happening here is that TickDuration's opCmp takes a 'ref' value. This is exactly the reason I *always* avoid ref on op*(), because it creates annoying situations like this one (in fact, I ran into this today as well). I don't know if auto ref would fix this.
There's no really no reason for opCmp to take anything other than a straight TickDuration in this case. TickDuration holds 1 long and that's it. It's not particularly large or complicated. In the general case, using auto ref would probably be the correct solution, but auto ref doesn't currently work for non-templated functions, which opCmp obviously isn't.
Commit pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/20fc5643c5f7111feb2caa55c8d86d1a50ea7f0e Merge pull request #172 from jmdavis/time Fix Issue 7606
Commit pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/67a03aa8061595e5e568ca60aacfa52f75bb155a Updated changelog for issue 7606.