StopWatch problem
Ali Çehreli
acehreli at yahoo.com
Tue Dec 5 22:25:12 UTC 2017
On 12/05/2017 01:45 PM, Jonathan M Davis wrote:
> On Tuesday, December 05, 2017 21:33:53 Joel via Digitalmars-d-learn
wrote:
>> void main() {
>> import std.datetime: Duration, msecs;
>> import std.datetime.stopwatch: StopWatch;
>>
>> StopWatch sw;
>> if (sw.peek.msecs) {
>>
>> }
>> }
>>
>> I get this error with the code:
>> z.d(6): Error: function core.time.dur!"msecs".dur (long length)
>> is not callable using argument types (Duration)
>
> core.time.msecs is an alias for core.time.dur!"msecs". It takes a
long for
> the number of milliseconds and returns a Duration. If you want to
convert a
> Duration to milliseconds, then use its member function, total. e.g.
> sw.peek.total!"msecs". It will convert the hnsecs in the duration to
msecs
> using integral math and return a long.
>
> If what you want is a floating point value like TickDuration.msecs does,
> then you'll have to do the math yourself with something like
> sw.peek.total!"hnsecs" / cast(real)convert!("seconds", "hnsecs")(1).
>
> https://dlang.org/phobos/core_time.html#.msecs
> https://dlang.org/phobos/core_time.html#.Duration.total
>
> - Jonathan M Davis
>
Selective imports complicates matters. Changing the imports lets it
compile with 2.076:
void main() {
import std.datetime;
import std.stdio: writeln;
StopWatch sw;
writeln(sw.peek.msecs);
}
Ali
More information about the Digitalmars-d-learn
mailing list