import std.typecons: Nullable; Nullable!int IndexOf(int[] arr, int val) { foreach (i, n; arr) { if (n == val) { //Error: inout method //std.typecons.Nullable!int.Nullable.this //is not callable using a mutable object return Nullable!int(i); } } return Nullable!int(); }
Note that array indexes are size_t, that are implicitly convertible to int only on 32 bit systems. This program compiles and works on 32 bits. And on 64 bit systems it can't work, you have to write "foreach (int i, n; arr)" or to use a cast.
Yeah, but the error message is really confusing.
*** This issue has been marked as a duplicate of issue 12322 ***