Boost C++ Libraries: Ticket #1422: const_iterator does not equate to value_type (or const value_type) https://svn.boost.org/trac10/ticket/1422 <p> In ptr_map, const_iterator does not represent value_type. Given this map: </p> <p> typedef boost::ptr_map&lt;DWORD, int&gt; BOOSTMAP; </p> <p> BOOSTMAP::value_type equates to: </p> <p> boost::ptr_container_detail::ref_pair&lt;DWORD, int* const&gt; </p> <p> BOOSTMAP::iterator does return this, but const_iterator returns: </p> <p> boost::ptr_container_detail::ref_pair&lt;DWORD, const int* const&gt; which is unlike std::map which represents const value_type for const_iterator. Since this is a different structure, it's incompatible with BOOSTMAP::value_type. </p> <p> The following code works using std::map: </p> <pre class="wiki">typedef std::map&lt;DWORD, int*&gt; STDMAP; int sample = 5; STDMAP sm; sm.insert( STDMAP::value_type(10,&amp;sample) ); STDMAP::iterator sfirst = sm.begin(); STDMAP::const_iterator scfirst = sm.begin(); STDMAP::value_type&amp; svt = *sfirst; const STDMAP::value_type&amp; scvt = *scfirst; </pre><p> But, the same fails on the last line with boost::ptr_map </p> <pre class="wiki">typedef boost::ptr_map&lt;DWORD, int&gt; BOOSTMAP; BOOSTMAP bm; DWORD key = 10; bm.insert( key, new int(5) ); BOOSTMAP::iterator bfirst = bm.begin(); BOOSTMAP::const_iterator bcfirst = bm.begin(); BOOSTMAP::value_type&amp; bvt = *bfirst; const BOOSTMAP::value_type&amp; bcvt = *bcfirst; </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1422 Trac 1.4.3 Thorsten Ottosen Sat, 17 Nov 2007 20:52:16 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1422#comment:1 https://svn.boost.org/trac10/ticket/1422#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> If you replace the last line with </p> <p> BOOST_MAP::const_reference bcvt = *bcfirst; </p> <p> it should work. </p> <p> Since a major design goal was to propagate constness, your line can never be made to work, unfortunately. </p> Ticket