associative arrays: iteration is finally here
Pelle Månsson
pelle.mansson at gmail.com
Fri Oct 30 01:15:17 PDT 2009
Nick Sabalausky wrote:
> "Pelle Månsson" <pelle.mansson at gmail.com> wrote in message
> news:hcaaro$15e4$1 at 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.
I, too, want opIn to work on arrays. On values. As a linear search. I do
not see why you would want to remove it on AA keys, though.
More information about the Digitalmars-d
mailing list