'in' for arrays?

Lionello Lunesu lio at lunesu.remove.com
Wed Dec 6 03:02:39 PST 2006


Egor Starostin wrote:
>> I keep wanting to say
>>    if (val in somearray) {
>>    }
> Me too.
> 
> For example, in Python I can write
> 
> if val in ('off','disable','no')

OK, granted, if (val in ["off","disable","no"]) does look cool, but a 
switch(val) would still be faster (uses binary search if I'm not mistaken).

Maybe D should get an alternative "if" for this construct:

switch(val) {
   case "off","disable","no":
      // code here
   default:
      break;
}

Anyway, supporting "in" for normal arrays has my vote. In my post I just 
mentioned a possible concern.

L.



More information about the Digitalmars-d mailing list