Thread overview
[Issue 23352] `in` and `out` foreach variables
Sep 21, 2022
Bolpat
Sep 22, 2022
Bolpat
Dec 17, 2022
Iain Buclaw
Feb 22, 2023
Bolpat
September 21, 2022
https://issues.dlang.org/show_bug.cgi?id=23352

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qs.il.paperinik@gmail.com

--
September 21, 2022
https://issues.dlang.org/show_bug.cgi?id=23352

elpenguino+D@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |elpenguino+D@gmail.com

--- Comment #1 from elpenguino+D@gmail.com ---
What is `out` supposed to be used for here? It seems like it'd be identical to `ref` in this context.

--
September 22, 2022
https://issues.dlang.org/show_bug.cgi?id=23352

--- Comment #2 from Bolpat <qs.il.paperinik@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.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=23352

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--
February 22, 2023
https://issues.dlang.org/show_bug.cgi?id=23352

--- Comment #3 from Bolpat <qs.il.paperinik@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.

In the simplest terms, you’re supposed to assign to an `out` variable. The D language does not enforce it, but e.g. C# does. D’s out is quite useless, it’s documenting intent more than anything. Besides that, you’re guaranteed that the object referred to is in its init state.

--