container stuff

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu May 27 06:30:08 PDT 2010


On 05/27/2010 06:49 AM, Don wrote:
> bearophile wrote:
>> Jonathan M Davis:
>>
>>> Well, I've never needed to do that particular operation on _any_
>>> container, so it does strike me as weird regardless. I've basically
>>> always been looking to remove a specific element or elements or to
>>> remove the element at a specific location.
>>
>> You have probably missed my other answer. But I can add some more.
>> That operation is common.
>
>> You use it every time you have a container that doesn't define a
>> deterministic order (like hash sets, hash associative arrays, and so
>> on) and you want to process and consume its items. In such collection
>> you can't ask to pop the last or first item because they are not
>> defined. So you pop out one randomly. I have used it many times in my
>> programs.
>
> When is it better to do it that way, rather than just iterating over all
> elements, and then completely empty the container?
> (Just curious -- I'm having trouble thinking of a use case for this
> feature).

Again, any worklist-based algorithm will remove and add work items 
without minding for a specific order.

http://cseweb.ucsd.edu/classes/sp00/cse231/report/node12.html


Andrei


More information about the Digitalmars-d mailing list