bearophile wrote:
Don:
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).

I'm having troubles understanding why two persons have troubles seeing use 
cases for this feature :-)

Iterating over the container and then emptying the container is two operations, 
you have to keep in mind to empty it, while if you pop items out of it 
progressively you just need to keep in mind to do one thing, and you avoid 
forgetting the final cleaning.

Yes, but if I understand correctly, the only reason to have removeAny _as a primitive_ is for speed. And iterating over the container followed by a single removal is almost always going to be much faster.

If, however, speed is not critical, removeAny can be a generic function -- call removeFront() if present, else call removeBack().
And your examples would work just fine with that.

I'm having trouble identifying a use case where it needs to be a primitive.

Reply via email to