in operator generalization

BCS BCS_member at pathlink.com
Fri Mar 17 17:23:21 PST 2006


Ivan Senji wrote:
> 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.

First of all, I don't have an opinion with regards to the "in" operator 
searching through an array.

Second, IIRC the intended use of AA is for the keys to be used to reference the 
content, not for storing the keys. However they do store the keys and would make 
a good device to store set of things.

I think the argument you refer to comes from a desirer for orthogonality. With 
an AA the "in" operator searches the things that goes in the [], using "in" on a 
normal array would search the things that come out when you index into the array.



More information about the Digitalmars-d mailing list