Should range foreach be iterating over an implicit copy?

bearophile bearophileHUGS at lycos.com
Thu May 17 02:53:01 PDT 2012


Nick Sabalausky:

> One side of the argument is that this behavior is correct and 
> expected since structs are value types, and iterating
> shouldn't consume the range.

In that D.learn thread I've shown that iterating on a fixed-size
array, that is a value, doesn't perform a copy of the array.


> Imagine, for example, an input range that read from stdin.
> Leaving that range unconsumed would make no sense at all.
> Actually, any input range can be expected to *not* leave an 
> uniterated copy behind: if it *could* have an uniterated
> copy left behind, it would be a forward range, not an input
> range.

Seems right.

Bye,
bearophile


More information about the Digitalmars-d mailing list