title: C++ Standard: Unexpected const_iterator in multiset
body: <p>I recently ran into an odd issue where I'd get a <code>const_iterator</code> instead of the expected <code>iterator</code> when iterating through a multiset. It turned out to be a non-issue for MSVC but g++ gave me an error:</p>
  
  <blockquote>
    <p>error: invalid initialization of
    reference of type 'myPtr&amp;' from
    expression of type 'const
    boost::shared_ptr'</p>
  </blockquote>
  
  <p>Relevant code:</p>
  
  <pre><code>typedef std::multiset&lt;myPtr&gt; myList;
  myList _mystuff;
  void tick(float dt)
  {
      for (myList::iterator i = _mystuff.begin(); i != _mystuff.end(); ++i)
      {
          myPtr &amp;mine = *i; // g++ problem here, not for MSVC
          // const myPtr &amp;mine = *i; works fine for g++
          mine-&gt;tick(dt);
      }
  }
  </code></pre>
  
  <p>Quite a bit of research revealed that is a problem with lots of previous discussion. I found these relevant bits:</p>
  
  <ul>
  <li><a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14990" rel="noreferrer">http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14990</a></li>
  <li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#322" rel="noreferrer">http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#322</a></li>
  <li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#103" rel="noreferrer">http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#103</a></li>
  <li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#279" rel="noreferrer">http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#279</a></li>
  <li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#528" rel="noreferrer">http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#528</a></li>
  </ul>
  
  <p>My background knowledge and grasp on the issue is limited and thus I'd like to know whether the standard doesn't define this behavior well enough in which case g++ and MSVC implement the behavior to their liking or whether either g++ or MSVC deviate from a well-defined standard.</p>
  
  <p>Thanks in advance.</p>