in not working for arrays is silly, change my view

aliak something at something.com
Mon Mar 2 20:25:24 UTC 2020


On Monday, 2 March 2020 at 15:50:08 UTC, Steven Schveighoffer 
wrote:
> On 3/2/20 6:39 AM, JN wrote:
>> On Saturday, 29 February 2020 at 21:56:51 UTC, Ali Çehreli 
>> wrote:
>>> Because you mentioned canFind, I think you want the semantics 
>>> to be "is there an element with this value." If so, it would 
>>> be confusing to use the same operator for two different 
>>> things: For associative arrays, it means "is there an element 
>>> accessible with this key."
>> 
>> Does it? I always viewed it as "is this value in list of keys"
>
> Array keys are the element index..
>
> So essentially:
>
> int[int] c1;
> int[] c2 = new int[4];
> c1[3] = 10;
> c2[3] = 10;
>
> assert(3 in c1); // true
> assert(3 in c2); // what should this do?
>
> -Steve

If in were to mean "is this value in list of keys" then to be 
consistent:

3 in c2 == 3 < c2.length


More information about the Digitalmars-d-learn mailing list