only parameters or stack-based variables can be `inout`
Steven Schveighoffer
schveiguy at gmail.com
Tue Nov 26 04:15:35 UTC 2024
On Monday, 25 November 2024 at 14:24:44 UTC, Bastiaan Veelo wrote:
> // Fishy:
> inout(E) gun(inout(E) e)
> {
> //writeln(e.to!string); // only parameters or stack-based
> variables can be `inout`
> writeln((cast(Unqual!E)e).to!string); // OK
> return e;
> }
Longstanding issue. When inout was first proposed, the point was
to prevent people from using in nonsensical ways. But this really
prevents reasonable template usage without all kinds of static
checks.
I went over this in my 2016 talk:
https://dconf.org/2016/talks/schveighoffer.html
1. inout should just be allowed to be returned when parameters
are not inout. The equivalent would just be const.
2. inout member fields should be fine.
-Steve
More information about the Digitalmars-d-learn
mailing list