Revised RFC on range design for D2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Sep 12 17:39:27 PDT 2008


Walter Bright wrote:
> Sean Kelly wrote:
>> I've found this invaluable at times.  And it's actually supported by 
>> C++ containers.
> 
> It's a bad idea, as it can screw up optimization. For example, if you 
> are using a change-and-swap method of updating a collection, the 
> collection cached by the foreach may get trashed.

I like the erase(remove) idiom used by STL, see 
http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Erase-Remove. Oddly 
enough, it's a variant of moveToFront, the function that allegedly 
nobody needs :o).

It's efficient and safe. Removing from a collection while iterating runs 
the risk of becoming quadratic if more than a few elements get removed.


Andrei


More information about the Digitalmars-d-announce mailing list