Reason for 'static struct'

Daniel Kozák via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 9 13:23:03 PST 2015


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



More information about the Digitalmars-d-learn mailing list