Parameter storage classes on foreach variables
Timon Gehr
timon.gehr at gmx.ch
Sat May 18 22:43:48 UTC 2024
On 5/17/24 20:59, Quirin Schroll wrote:
> As of now, `foreach` admits `ref` variables as in `foreach (ref x; xs)`.
> There, `ref` can be used for two conceptually different things:
> * Avoiding copies
> * Mutating the values in place
>
> If mutating in place is desired, `ref` is an excellent choice.
> However, if mere copy avoiding is desired, another great option would be
> `in`.
I contest that `in` is a great option every time mere avoiding of copies
is desired (because it implies transitive `const`).
In general, extending `foreach` to `in` and `out` makes some sense, but
`out` is likely to be quite controversial, especially the output range
lowering. When I think of `foreach`, I think of consuming a range, not
producing one.
More information about the dip.ideas
mailing list