foreach() behavior on ranges
Alexandru Ermicioi
alexandru.ermicioi at gmail.com
Wed Aug 25 11:26:51 UTC 2021
On Wednesday, 25 August 2021 at 11:04:35 UTC, Steven
Schveighoffer wrote:
> It never has called `save`. It makes a copy, which is almost
> always the equivalent `save` implementation.
>
> -Steve
Really?
Then what is the use for .save method then?
The only reason I can find is that you can't declare constructors
in interfaces hence the use of the .save method instead of copy
constructor for defining forward ranges.
We have now two ways of doing the same thing, which can cause
confusion. Best would be then for ranges to hide copy constructor
under private modifier (or disable altoghether), and force other
range wrappers call .save always, including foreach since by not
doing so we introduce difference in behavior between ref and
value forward ranges (for foreach use).
More information about the Digitalmars-d-learn
mailing list