What do the 'in' and 'out' keywords mean in D?
d
Solution
Yeah, you basically get it. `in` expands to `const scope` meaning you cannot change the variable (or anything it points to) and also are not supposed to keep a reference to it anywhere (`scope` is not actually implemented in most cases though). Basically, `in` is look, don't touch.
`out` means the given variable receives a value. It is very similar to `ref` - changes to it inside the function are also seen on the outside - with the small difference that out variables are initialized to their normal init value, clearing the value they had before the function was called.
Basically, `void foo(out int a) {}` == `void foo(ref int a) { a = 0; /* inserted automatically */ }`
Problem
What do the `in` and `out` keywords in D actually mean and do? From looking around at functions using these for their parameters I understand that the `in` keyword is used for function input and the `out` keyword is used for parameters which are basically passed by reference. Is that understanding correctly, and what do they actually allow or disallow a programmer to do?