Weird interaction of design choices: Duration + sum

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Oct 13 19:31:24 UTC 2017


On Friday, October 13, 2017 18:36:58 Luís Marques via Digitalmars-d wrote:
> If you do this:
>
>      import std.algorithm : sum;
>      import core.time : Duration;
>
>      Duration[] parts;
>      auto total = parts.sum;
>
> You'll get an error ("struct core.time.Duration member this is
> not accessible"). That's because the Duration constructor is
> private, and `sum` calls `sum(r, Unqual!Seed(0))`. BTW, not the
> most helpful of messages for beginners, maybe this could be
> phrased to say the ctor is private?

Well, that's a general issue separate from sum or Duration specifically.
"Not accessible" is more general than talking about private, and it's
something that I would expect most C++ or D programmers to know, but I'm not
exactly in the best place to know what someone coming from another language
would know or find confusing. Certainly, if you feel that specifically
indicating the the problem is that the constructor is private would make for
a better error message, then feel free to create an enhancement request for
it:

https://issues.dlang.org

- Jonathan M Davis




More information about the Digitalmars-d mailing list