foreach() behavior on ranges
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Wed Aug 25 10:06:10 UTC 2021
On Tuesday, 24 August 2021 at 09:15:23 UTC, bauss wrote:
> A range should be a struct always and thus its state is copied
> when the foreach loop is created.
That's quite a strong assumption, because its state might be a
reference type, or it might not _have_ state in a meaningful
sense -- consider an input range that wraps reading from a
socket, or that just reads from `/dev/urandom`, for two examples.
Deterministic copying per foreach loop is only guaranteed for
forward ranges.
More information about the Digitalmars-d-learn
mailing list