'in' for arrays?

Chris Nicholson-Sauls ibisbasenji at gmail.com
Wed Dec 6 12:23:57 PST 2006


Lionello Lunesu wrote:
> Bill Baxter wrote:
>> I keep wanting to say
>>   if (val in somearray) {
>>   }
> 
> Wait! That's just it!
> 
> It's "KEY in CONTAINER" and the KEY of a regular array is the index, not 
> the value. So dare I suggest the following instead?
> 
> if (index in somearray) {
> }
> 
> This "in" would be:
> (cast(size_t)index < somearray.length?&somearray[index]:null)
> 
> Totally analogous to the associative array. And it also solves the 
> "Length comparison" issue.
> 
> L.

Now this I actually like... Can already think of places I could use it, such as in Bovis 
during symbol/id lookups.  Its a nice idea.  (Might just add it to Cashew in the meantime.)

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list