how is this array subtyping inside struct (bug?) possible?

mw mingwu at gmail.com
Mon Aug 10 18:36:20 UTC 2020


On Monday, 10 August 2020 at 18:29:56 UTC, mw wrote:
> and where in this doc on range:
>
> https://tour.dlang.org/tour/en/basics/ranges
>
> it is mentioned that: the length property of the range will be 
> changed after the range is "consumed" by foreach loop?
>
> ```
> foreach (element; range)
> {
>     // Loop body...
> }
> it's internally rewritten similar to the following:
>
> for (auto __rangeCopy = range;
>      !__rangeCopy.empty;
>      __rangeCopy.popFront())
>  {
>     auto element = __rangeCopy.front;
>     // Loop body...
> }
> ```

And wait, ... did I saw "__rangeCopy" here?  it should be a 
*copy*?!




More information about the Digitalmars-d mailing list