Comparison of TickDuration and StopWatch.peek

Matej Nanut matejnanut at gmail.com
Tue Feb 28 10:15:01 PST 2012


Hello everyone,

I have the following 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.
    { }
}


I would like to know why the second ‘while’ doesn't compile. The error is:

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

which I don't really understand. There shouldn't be a difference in
‘<’ and ‘>=’ apart from their result, or should there be? =/ Same
thing happens for ‘>’.

Also, I can use ‘peek’ without parenthesis even though it isn't marked
as @property on dlang.org, am I missing something? I probably read the
spec incorrectly somewhere for this one.

Thanks, Matej


More information about the Digitalmars-d-learn mailing list