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