"Pelle Månsson" <pelle.mans...@gmail.com> wrote in message news:hcaaro$15e...@digitalmars.com... > I think foreach should be consistent with opIn, that is, > if (foo in aa) { //it is in the aa. > foreach (f; aa) { // loop over each item in the aa > //I expect foo to show up in here, since it is "in" the aa. > } > } > > I use key iteration more than I use value iteration, and it is what I am > used to. It is, as you say, a matter of preference.
I've thought for a long while that "in" should be value-based (so you can do things like "if(foo in [1,2,7,9])" instead of the not-as-nice "if([1,2,7,9].contains(foo))"), and that there should be some other way to check for the existance of a key (like "aa.hasKey(key)" or "key in aa.keys", or something like that). I need to check for values in an array much more often than I need to check for keys in an aa.