Why 'in' works only for assoc arrays?
Ali Çehreli
acehreli at yahoo.com
Sat Dec 28 04:44:43 UTC 2024
On 12/27/24 6:14 PM, JN wrote:
> "in" only works for associative arrays by checking for existence of a
> provided key in an associative array. E.g.:
[...]
> Naturally, a user will try to use it to check for existence of a value
> in an array
That's not natural at all because if it worked that way, another user
would complain about 'in's inconsistency between associative arrays and
arrays: keys vs. values.
> onlineapp.d(7): `in` is only allowed on associative arrays
> onlineapp.d(7): perhaps use `std.algorithm.find("John", names)`
That help is not very useful but it escapes any criticism because of the
clever user of the word "perhaps". Yes, std.algorithm.find could be used
but the correct function to use in this case is std.algorithm.canFind.
Ali
More information about the Digitalmars-d-learn
mailing list