Boost C++ Libraries: Ticket #2484: Const-overload needed for bimap associative_container_adaptor::count() https://svn.boost.org/trac10/ticket/2484 <p> Would it be possible to include a const-overloaded version of count() for associative containers in boost::bimaps? I had some code like this: </p> <pre class="wiki">void CMyClass::func(size_t key) const { size_t num_elements=_member_map.count(key); ... } </pre><p> where _member_map was a std::map, and it worked fine. When I changed _member_map to a bimap, the equivalent code: </p> <pre class="wiki">void CMyClass::func(size_t key) const { size_t num_elements=_member_map.left.count(key); ... } </pre><p> gives an error, because count() is non-const (whereas GCC's std::map::count() is const). That's presumably done because the STL documentation declares count() as non-const (not sure why), but it doesn't seem there would be any harm in adding a const-overload so that this kind of code would compile when the underlying type supports it. The attached patch fixes the problem for me. </p> <p> Thanks </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2484 Trac 1.4.3 mlcreech@… Fri, 07 Nov 2008 16:49:30 GMT attachment set https://svn.boost.org/trac10/ticket/2484 https://svn.boost.org/trac10/ticket/2484 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">07-const-count-overload.patch</span> </li> </ul> Ticket Gonzalo Matamala <gonmator@…> Wed, 09 Sep 2009 09:19:28 GMT attachment set https://svn.boost.org/trac10/ticket/2484 https://svn.boost.org/trac10/ticket/2484 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">associative_container_adaptor-count-const-fix.patch</span> </li> </ul> Ticket Gonzalo Matamala <gonmator@…> Wed, 09 Sep 2009 09:20:03 GMT version changed https://svn.boost.org/trac10/ticket/2484#comment:1 https://svn.boost.org/trac10/ticket/2484#comment:1 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.36.0</span> → <span class="trac-field-new">Boost 1.39.0</span> </li> </ul> Ticket Gonzalo Matamala <gonmator@…> Wed, 09 Sep 2009 09:28:33 GMT <link>https://svn.boost.org/trac10/ticket/2484#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2484#comment:2</guid> <description> <p> I think overloading count() is a wrong fix. The right fix is just adding const qualifier. </p> <p> The C++ standard declare const() member of map, multimap, set and multi set as const [23.3.1, 23.3.2, 23.3.3, 23.3.4]: </p> <pre class="wiki">size_type count(const key_type&amp; x) const; </pre><p> Also, the bimap documentation (<a href="http://www.boost.org/doc/libs/1_40_0/libs/bimap/doc/html/boost_bimap/reference/set_of_reference.html#boost_bimap.reference.set_of_reference.__multi__set_of_views.set_operations">http://www.boost.org/doc/libs/1_40_0/libs/bimap/doc/html/boost_bimap/reference/set_of_reference.html#boost_bimap.reference.set_of_reference.__multi__set_of_views.set_operations</a>) declare count() member of </p> <pre class="wiki">[multi]set_of as const: template&lt; class CompatibleKey &gt; size_type count(const key_type &amp; x) const; </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Matias Capeletto</dc:creator> <pubDate>Sat, 09 Jan 2010 21:34:05 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/2484#comment:3 https://svn.boost.org/trac10/ticket/2484#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Matias Capeletto Fri, 15 Jan 2010 14:29:19 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2484#comment:4 https://svn.boost.org/trac10/ticket/2484#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket