title: std::list::erase does not invalidate other iterators and references
body: <p>I read in cppreference that <code>erase</code> does not affect iterators and references other than erased ones. But if I don't understand why following code does not work:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  
  int main()
  {
    std::list&lt;int&gt; lst;
    lst.push_back(5);
    lst.push_back(10);
    lst.push_back(20);
  
    int i = 0;
    for (auto it = lst.begin(); it != lst.end(); ++it) // FIRST LOOP
    {
      if (i == 1) { lst.erase(it); }
      ++i;
    }
  
    for (auto el : lst) // SECOND LOOP
    {
      std::cout &lt;&lt; el &lt;&lt; std::endl;
    }
  
    return 0;
  }
  
  </code></pre>
  <p>First loop never stops which causes <code>Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)</code>. But I don't erase everything works fine.
  So what is the problem?</p>
  <p>UPD:
  Tried to change</p>
  <pre class="lang-cpp prettyprint-override"><code>...
  for (auto it = lst.begin(); it != lst.end(); ++it) // FIRST LOOP
  ...
  </code></pre>
  <p>to</p>
  <pre class="lang-cpp prettyprint-override"><code>...
  auto end = lst.end();
    for (auto it = lst.begin(); it != end; ++it) // FIRST LOOP
  ...
  </code></pre>
  <p>but it did not help</p>