title: why do values returned by std::end() change as the container changes, but not with std::begin()?
body: <p>I have a <code>std::list</code> that I am inserting items into, and I have a <code>std::unordered_map</code> where I want to store iterators to the elements inserted into the <code>std::list</code> (I am implementing a LRU cache). The following code does not give me the output I expect:</p>
  <pre><code>#include &lt;list&gt;
  #include &lt;unordered_map&gt;
  #include &lt;iostream&gt;
  
  
  int main()
  {
      std::list&lt;int&gt; l;
      std::unordered_map&lt;int, std::list&lt;int&gt;::iterator&gt; listItems;
      
      for (int i = 0; i &lt; 5; i++)
      {
          l.push_back(i);
          listItems[i] = std::end(l);
      }
          
  
      for (int i = 0; i &lt; 5; i++)
          std::cout &lt;&lt; *(listItems[i]) &lt;&lt; &quot; &quot;;
      std::cout &lt;&lt; std::endl;
  
  }
  </code></pre>
  <p>The output here is <code>5 5 5 5 5</code> - the output I want/expect is <code>0 1 2 3 4</code>. I would have guessed looking at this code that <code>std::end</code> returns an iterator to the last element of the list, which is copied into listItems[i], but this is clearly not what is happening. I am confused why adding items to the list affects the result of earlier calls to <code>std::end</code></p>
  <p>However, if I change the first loop to</p>
  <pre><code>for (int i = 0; i &lt; 5; i++)
  {
      l.push_front(i);
      listItems[i] = std::begin(l);
  }
  </code></pre>
  <p>I get the output I expect - <code>0 1 2 3 4</code>. So what is the difference here between <code>push_front</code> and <code>push_back</code>, and <code>std::begin</code> and <code>std::end</code></p>