Reason for 'static struct'
Daniel Kozak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Dec 10 00:45:25 PST 2015
Yes, exactly. Some people even use static if it is not needed because it is
harmless. And remove it only when enclosing context is demand.
Dne 9. 12. 2015 22:40 napsal uživatel "Jon D via Digitalmars-d-learn" <
digitalmars-d-learn at puremagic.com>:
> On Wednesday, 9 December 2015 at 21:23:03 UTC, Daniel Kozák wrote:
>
>> V Wed, 09 Dec 2015 21:10:43 +0000
>> Jon D via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
>> napsáno:
>>
>> There is a fair bit of range related code in the standard library
>>> structured like:
>>>
>>> auto MyRange(Range)(Range r)
>>> if (isInputRange!Range)
>>> {
>>> static struct Result
>>> {
>>> private Range source;
>>> // define empty, front, popFront, etc
>>> }
>>> return Result(r);
>>> }
>>>
>>> I'm curious about what declaring the Result struct as 'static' does, and
>>> if there are use cases where it be better to exclude the static qualifier.
>>>
>>> --Jon
>>>
>>
>> It make it non-nested struct: https://dlang.org/spec/struct.html#nested
>>
>
> Thanks. So, is in the example above, would the advantage be that 'static'
> avoids saving the enclosing state, which is not needed?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20151210/0514e173/attachment.html>
More information about the Digitalmars-d-learn
mailing list