container stuff

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed May 26 18:49:21 PDT 2010


On 05/26/2010 08:30 PM, Jonathan M Davis wrote:
> Andrei Alexandrescu wrote:
>
>> On 05/26/2010 06:07 PM, Jonathan M Davis wrote:
>>> Looks interesting overall. There is one function, however, which makes no
>>> sense to me: removeElement()/stableRemoveElement().
>>>
>>> So, it basically removes a random element from the container? It could be
>>> quite consistent as to which element it removes from the container (it
>>> being implementation-dependent), but effectively, it removes a random
>>> element? What's the point of that? I can't remember the last time - if
>>> ever - that I wanted to remove an element from a container and I didn't
>>> care which. Or am I misunderstanding what it does?
>>>
>>> - Jonathan M Davis
>>
>> If the container is a worklist with items to work on, it sometimes
>> doesn't matter in which order you extract them.
>>
>> Andrei
>
> Well, my first reaction would be that that would be needed rarely enough
> that there's no point in putting it in the API. You could just use
> removeFront() or removeBack(), or you could grab a random element from the
> container and remove that.

SList can't implement removeBack() and Array can't implement 
removeFront(). Only a few containers can implement grabbing a random 
element within the complexity constraints of removeElement().

> But maybe there are container types where it
> really makes sense, and having it in the API could be useful. Still, it
> strikes me as a really weird function to have. Of course, if you really
> think that it's going to be useful, leave it in. Unlike pretty much all the
> others though, it's not one I ever expect to use.

It might not be weird if you want to write container-independent code.


Andrei



More information about the Digitalmars-d mailing list