Prevent copy of range in foreach
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 31 19:50:55 PDT 2016
On Wednesday, 31 August 2016 at 23:38:21 UTC, Yuxuan Shui wrote:
>
> OK, this would work for cases like containers. But what if I
> represent buffered network input as a range (like File.byLine),
> and I don't want to copy the buffer all the time? Any
> suggestion on how to do that correctly?
Then the range should be constructed with a slice of the buffer
if it's an array or with something pointer-based if it isn't
(which requires a bit of bookkeeping). Ranges should be
lightweight and should never require copying of the underlying
data.
More information about the Digitalmars-d-learn
mailing list