[Issue 23352] `in` and `out` foreach variables

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 22 13:03:51 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23352

--- Comment #2 from Bolpat <qs.il.paperinik at gmail.com> ---
(In reply to elpenguino+D from comment #1)
> What is `out` supposed to be used for here? It seems like it'd be identical
> to `ref` in this context.

An `out` parameter is not the same as a `ref` parameter. The difference is
small, but it is there. You are not supposed to get information from an `out`
parameter; instead, you’re supposed to assign to it. You may, of course,
afterwards read the information you put in. `out` generally is primary
documenting intent; if it were for the semantic differences alone, `ref`
subsumes it.

Also note that, on loops, because of a bug, `ref` is a suggestion and reference
semantics is not enforced. `out` would be new and enforcement of reference
semantics would not break anyone’s code.

--


More information about the Digitalmars-d-bugs mailing list