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

Alex sascha.orlov at gmail.com
Wed Sep 18 10:25:57 UTC 2019


On Tuesday, 17 September 2019 at 18:10:40 UTC, Brett wrote:
>> 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).

It is also expressive to define
size_t y;
and to check y only for being < x.length.

An array does not have keys. It has indices.


More information about the Digitalmars-d mailing list