c++ - Erase/Remove contents from the map (or any other STL container) while iterating it -


Allegedly, you can not erase / delete an element in a container, whereas walking as an iterator becomes invalid What are the (safe) ways to remove elements that meet a certain condition? Please do not have only STL, no boost or tr1.

Edit Is it a very attractive way if I want to erase several elements that meet certain criteria, e-mail or erase the algorithm?

  bool isOdd (int i) {return (i & amp; 1)! = 0; } Int a [] = {1,2,3,4,5}; Of vector & lt; Int & gt; V (a, a +5); V.erase (remove_if (v.begin (), v.end (), bind1st (equal_to & lt; int> (), 4)), v.end ()); // v contains {1,2,3,5} v.erase (remove_if (v.begin (), v.end (), isodod), v.end ()); // v contains {2}  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -