On Tuesday, 26 November 2024 at 04:15:35 UTC, Steven Schveighoffer wrote:
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.

In this case the specific limitation getting in the way is that you cannot pass an `inout` value as an argument to a [template value parameter][1].

[1]: https://dlang.org/spec/template.html#template_value_parameter

Reply via email to