associative arrays: iteration is finally here

Steven Schveighoffer schveiguy at yahoo.com
Thu Oct 29 05:52:42 PDT 2009


On Wed, 28 Oct 2009 20:08:34 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> Denis Koroskin wrote:
>> On Wed, 28 Oct 2009 23:18:08 +0300, Andrei Alexandrescu  
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>
>>>> I'd also like you to add a few things in an AA interface.
>>>>  First, opIn should not return a pointer to Value, but a pointer to a  
>>>> pair of Key and Value, if possible (i.e. if this change won't  
>>>> sacrifice performance).
>>>
>>> I'm coy about adding that because it forces the implementation to hold  
>>> keys and values next to each other. I think that was a minor mistake  
>>> of STL - there's too much exposure of layout details.
>>>
>>  It doesn't have to be the case: key and value are both properties  
>> (i.e. methods), and they doesn't have to be located next to each other.
>
> I see. So you want a pointer to an elaborate type featuring a key and a  
> value.

It could return a struct holding both pointers, instead of a pointer to a  
struct.  I don't see this as unreasonable (in fact, it's what I do in  
dcollections, see the cursor types).  An implementation which stores the  
two close together in actuality may only require one pointer.

The only drawback of this is it can't be part of a formal interface, since  
the return type is defined by the derived type.

-Steve



More information about the Digitalmars-d mailing list