digitalmars.D.learn - Reason for 'static struct'
- Jon D (16/16) Dec 09 2015 There is a fair bit of range related code in the standard library
- Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d-learn (4/23) Dec 09 2015 V Wed, 09 Dec 2015 21:10:43 +0000
- Jon D (3/28) Dec 09 2015 Thanks. So, is in the example above, would the advantage be that
- Daniel Kozak via Digitalmars-d-learn (7/36) Dec 10 2015 Yes, exactly. Some people even use static if it is not needed because it...
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
Dec 09 2015
V Wed, 09 Dec 2015 21:10:43 +0000 Jon D via Digitalmars-d-learn <digitalmars-d-learn 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. --JonIt make it non-nested struct: https://dlang.org/spec/struct.html#nested
Dec 09 2015
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 puremagic.com> napsáno:Thanks. So, is in the example above, would the advantage be that 'static' avoids saving the enclosing state, which is not needed?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. --JonIt make it non-nested struct: https://dlang.org/spec/struct.html#nested
Dec 09 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=C5=BEivatel "Jon D via Digitalmars-d-learn" = < digitalmars-d-learn puremagic.com>:On Wednesday, 9 December 2015 at 21:23:03 UTC, Daniel Koz=C3=A1k wrote:dV Wed, 09 Dec 2015 21:10:43 +0000 Jon D via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> naps=C3=A1no: There is a fair bit of range related code in the standard librarystructured 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, an=er.if there are use cases where it be better to exclude the static qualifi=Thanks. So, is in the example above, would the advantage be that 'static' avoids saving the enclosing state, which is not needed?--JonIt make it non-nested struct: https://dlang.org/spec/struct.html#nested
Dec 10 2015