title: C++ map.erase() causes unwanted balancing
body: <p>I have a <code>map&lt;uint, Order*&gt; orders</code> where Order is a defined class with applicable fields such as id, time, price and volume. I also have a thread which listens for incoming order additions and deletions for the map defined below.</p>
  
  <pre><code>void System::OrderDeleted_Thread(unsigned int order_id)
  {
      if(orders.find(order_id) != orders.end())
      {
              Order* order = orders[order_id];
              orders.erase(order_id);
              delete order;
      }
  }
  </code></pre>
  
  <p>My problem is very similar to this one:</p>
  
  <p><a href="https://stackoverflow.com/q/2869183/1143465">Segmentation fault in std function std::_Rb_tree_rebalance_for_erase ()</a></p>
  
  <p>My question is, how can I iterate through my orders map without the program giving me an error when it comes time to re balance the tree? Just like the solution in the link says, I have taken out the .erase(uint) method and gotten it to work. Unfortunately, I cannot keep a map of several tens of thousands keys around.</p>
  
  <p>Thanks in advance!</p>