www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19525] New: Duration is not usable with zero-arg


          Issue ID: 19525
           Summary: Duration is not usable with zero-arg std.algorithm.sum
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: simen.kjaras gmail.com


import std.algorithm : sum;
import std.datetime : Duration, minutes;

unittest {
    // Error: struct `core.time.Duration` member this is not accessible
    assert([1.minutes].sum() == 1.minutes);

The above code fails because sum() tries to construct Duration(0), which fails
to compile. The error message (member this is not accessible) leaves something
to be desired.

Workaround for now: [1.minutes].sum(Duration.zero).

Suggested fix: have sum() check if Seed.zero exists, and use that.

Dec 30 2018