title: Efficiently remove last element from std::list
body: <p>This seems like a simple problem, and it is certainly doable, but I'd like to do it efficiently. </p>
  
  <p><strong>The Objective</strong>:<br>
  Remove the last element from a std::list if it meets a condition.</p>
  
  <p><strong>The Problem</strong>:<br>
  My compiler (MSVC++ 10) is unhappy about casting a reverse iterator to a const iterator for a method call to std::list.erase(). The message is: </p>
  
  <blockquote>
  <pre><code>error C2664: 'std::_List_iterator&lt;_Mylist&gt;
   std::list&lt;_Ty&gt;::erase(std::_List_const_iterator&lt;_Mylist&gt;)' : cannot
   convert parameter 1 from 'std::reverse_iterator&lt;_RanIt&gt;' to
   'std::_List_const_iterator&lt;_Mylist&gt;'
  </code></pre>
  </blockquote>
  
  <p><strong>The Code I Tried</strong>:</p>
  
  <pre><code>std::list&lt;mytype&gt; mylist;
  
  // lots of code omitted for clarity
  bool ends_badly = true;
  
  while(ends_badly &amp;&amp; mylist.size() &gt; 0)
  {
      auto pos = mylist.crbegin(); // Last element in the list
      if ((*pos)-&gt;Type() == unwanted)
      {
          mylist.erase(pos); // Here is where the compiler complains
      }
      else
      {
          ends_badly = false;
      }
  }
  </code></pre>
  
  <p>I can get around this by using forward iterators and looping through the list to the end, but that's so cumbersome. The compiler is OK with a forward iterator in this context, and I tried casting a the reverse iterator to a const iterator but the compiler didn't like that either.</p>
  
  <p>Erasing a list element from a bidirectional list using a reverse iterator seems like a reasonable thing. Is there something obvious I'm missing here?</p>