'in' for arrays?

Stewart Gordon smjg_1998 at yahoo.com
Thu Dec 7 14:26:15 PST 2006


Bill Baxter wrote:
> I keep wanting to say
>   if (val in somearray) {
>   }
> 
> but 'in' doesn't work for arrays...  Is there any reason why not?
<snip>

You appear to be wanting it to find a given _value_ in an array. 
Several people have requested this.  The problem is that it would create 
a confusing inconsistency with associative arrays, in which it is 
defined to find a given _key_.

Logically, if in does anything on linear arrays, then it should check 
whether the given index is within the array's bounds.  This isn't just 
purism - it's also a generic programming concern.

Moreover, if we were to define an operator that finds a given _value_ in 
a linear array, we ought to have it for AAs too.

Stewart.



More information about the Digitalmars-d mailing list