in operator generalization

Ivan Senji ivan.senji_REMOVE_ at _THIS__gmail.com
Fri Mar 17 16:54:02 PST 2006


BCS wrote:
> Les Baker wrote:
>> Looking through old NG posts I found this one by Ben Hinkle last year
>> about extending the "in" operator to support static/dynamic arrays.
>>
>> http://www.digitalmars.com/d/archives/digitalmars/D/25164
>>
>> Was this ever totally dismissed?  It just seemed to fall off the
>> radar.  I'm liking the concept though; I don't know how many times
>> I've written loops in quickie utility programs just to hunt for a item
>> and return it.  I would also additionally suggest (if it hasn't
>> already been) that "in" be overloadable so that if D supports other
>> data structures in the standard library that they can use that syntax
>> as well.
>>
>> The only disadvantage I can think of is that when a developer sees
>> "in", he/she can't assume it's a constant time operation anymore.  I
>> think the increase in utility outweights that though.
>>
>> Thoughts?
>>
>> Les Baker
> 
> Actually this would be backwards, "in" determines if the given value is
> a key for the AA. Using it to examine the contents would be something
> different than it's current meaning, but this might not be a bad idea.

I didn't understand before nor do I understand why this was always an
argument against 'in' for arrays?

float[MyObject] array; -> stores MyObjects
MyObject[] 	array; -> stores MyObjects

AA are different from normal arrays. In AA's the index is the thing you
are storing, and it makes sense to search for it.



More information about the Digitalmars-d mailing list