Denis Koroskin wrote:
On Wed, 28 Oct 2009 23:18:08 +0300, Andrei Alexandrescu <seewebsiteforem...@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.

Second, AA.remove method should accept result of opIn operation to avoid an additional lookup for removal:
 if (auto value = key in aa) {
    aa.remove(key); // an unnecessary lookup
}

I'll make aa.remove(key) always work and return a bool that tells you whether there was a mapping or not.


Err... How does it solve the double lookup problem?

Your test looks something up and then removes it.


Andrei

Reply via email to