title: Vector erase iterator outside range
body: <p>Porting some code from my game engine from Mac to Windows in C++, and I get this runtime error: "Vector erase outside range". It works on Mac!</p>
  
  <pre><code>void Entity::runDeferreds() {
      for (auto it = deferreds.begin(); it != deferreds.end(); /* nothing */ ) {
          if (it-&gt;Condition()) {
              it-&gt;Execution();
  
              it = deferreds.erase(it);
          } else {
              ++it;
          }
      }
  }
  </code></pre>
  
  <p>This iterates thru a list of "deferred" tasks, which are stored in a <code>std::vector&lt;DeferredCall&gt;</code> called <code>deferreds</code>. If the <code>DeferredCall</code>'s <code>Condition()</code> is fulfilled, then its <code>Execution()</code> is run, and it should be removed from the <code>vector</code>. However, instead, I get the aforementioned error! </p>
  
  <p>DeferredCall looks like this, not that it's too important:</p>
  
  <pre><code>struct DeferredCall {
      std::function&lt;bool()&gt; Condition;
      std::function&lt;void()&gt; Execution;
  };
  </code></pre>
  
  <p>Help?!</p>
  
  <p><strong>EDIT:- Alternative Method</strong></p>
  
  <p>I also tried this, again working on Mac:</p>
  
  <pre><code>deferreds.erase(std::remove_if(deferreds.begin(), deferreds.end(),
      [](DeferredCall &amp;call) {
              if (call.Condition()) {
                  call.Execution();
                  return true;
              }
  
              return false;
          }
      ), deferreds.end());
  </code></pre>
  
  <p>However, in this case I get "vector iterators incompatible".</p>