Compile Errors - std::set with const members
<p>I can't for the life of me figure out what's wrong with this code:</p>

<pre><code>ClassA &amp; doSomething (std::set&lt;boost::shared_ptr&lt;ClassB const&gt; const &gt; const &amp; someSet)
{
  std::set&lt;boost::shared_ptr&lt;ClassB&gt; &gt; secondSet;
  for (std::set&lt;boost::shared_ptr&lt;ClassB const&gt; const &gt;::const_iterator it = someSet.begin(); it != someSet.end(); it++)
  {
    if (checkSomething(*it))
      secondSet.insert(boost::const_pointer_cast&lt;ClassB&gt;(*it));
  }
}
</code></pre>

<p>When I try to compile, I get the following errors at line 4 (the start of the for loop) from g++:</p>

<pre><code>/usr/include/c++/4.4/ext/new_allocator.h:79: error: ‘const _Tp* __gnu_cxx::new_allocator&lt;_Tp&gt;::address(const _Tp&amp;) const [with _Tp = const boost::shared_ptr&lt;const ClassB&gt;]’ cannot be overloaded
/usr/include/c++/4.4/ext/new_allocator.h:76: error: with ‘_Tp* __gnu_cxx::new_allocator&lt;_Tp&gt;::address(_Tp&amp;) const [with _Tp = const boost::shared_ptr&lt;const ClassB&gt;]’
</code></pre>

<p>If I change the <code>std::set</code> declaration to contain non-const <code>boost::shared_ptr</code> the code compiles perfectly, but that mean I won't be able to enforce const-correctness in my code.</p>

<p>Has anyone got any idea as to what might be causing these errors? I've searched both Google &amp; StackOverflow without any luck.</p>

<p>Here is a minimum (non-)working example:</p>

<pre><code>#include &lt;set&gt;
#include &lt;boost/shared_ptr.hpp&gt;

class ClassB;

class ClassA
{
   public:
      ClassA &amp; doSomething (std::set&lt;boost::shared_ptr&lt;ClassB const&gt; const &gt; const &amp; someSet);
};

ClassA &amp; doSomething (std::set&lt;boost::shared_ptr&lt;ClassB const&gt; const &gt; const &amp; someSet)
{
   std::set&lt;boost::shared_ptr&lt;ClassB&gt; &gt; secondSet;
   for (std::set&lt;boost::shared_ptr&lt;ClassB const&gt; const &gt;::const_iterator it = someSet.begin(); it != someSet.end(); it++)
   {
      if (checkSomething(*it))
         secondSet.insert(boost::const_pointer_cast&lt;ClassB&gt;(*it));
   }

   return (*this);
}
</code></pre>
