Is there any reason why in can't work with dynamic arrays?

Brett Brett at gmail.com
Tue Sep 17 18:10:40 UTC 2019


On Tuesday, 17 September 2019 at 17:46:09 UTC, Adam D. Ruppe 
wrote:
> On Tuesday, 17 September 2019 at 17:43:39 UTC, Brett wrote:
>> T[] x;
>>
>> if (y in x) ...
>>
>> It just checks to see if y is in between 0 and length.
>
> Most people asking for this want it to check that the *value* y 
> is in the array x, which is rejected for requiring a linear 
> search.
>
> But your idea could be done quickly, just I expect it would 
> cause confusion with the people asking for the other.
>
> I like to just check if y >= 0 && y < x.length which is more 
> clear  anyway.


Yes, I could see that, but it doesn't do that with AA's so but I 
could see how it could be problematic.

Alternatively, have a keys for a DA:

then one can do

if (y in x.keys)

and this is far more expressive so there is no confusion and also 
works with AA's(and would not result in keys having to be created 
because it is semantically the same as (y in x) if x is an AA).






More information about the Digitalmars-d mailing list