[Issue 15651] filter: only parameters or stack based variables can be inout

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 22 14:09:34 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=15651

Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com

--- Comment #3 from Steven Schveighoffer <schveiguy at yahoo.com> ---
(In reply to Simen Kjaeraas from comment #1)
> This issue is only partially fixable - filter() could use the solution
> described in issue 13428 to turn inout(T) into const(T). This would lead to
> fun() returning a const(D)[] result instead of inout(D)[], so it's not a
> complete solution.

It's fully fixable -- if we can create an filter of inout elements. As I
mentioned in issue 9983, this simply involves allowing structs to declare inout
members. In fact, we should allow inout to be used ANYWHERE, except global
variables (as putting inout variables in global space can change the meaning
from call to call). They will just be another type of immutable in functions
which don't have inout parameters, or when used in structs outside of inout
functions.

(In reply to anonymous4 from comment #2)
> See also workaround in issue 9983

This is not a valid workaround, as an inout filter would not be iterable.

I actually thought that maybe with closures, we could make a "workaround" but
it doesn't work because there's no way to return an inout from a function that
has no inout parameters. Another stupid limitation that we should omit.

I'd try my hand at an inout improvement DIP, but I feel it would likely be
rejected on principle, since inout is so disfavored by leadership.

--


More information about the Digitalmars-d-bugs mailing list