Opened 9 years ago

Closed 8 years ago

#2484 closed Patches (fixed)

Const-overload needed for bimap associative_container_adaptor::count()

Reported by: mlcreech@… Owned by: Matias Capeletto
Milestone: Boost 1.38.0 Component: bimap
Version: Boost 1.39.0 Severity: Problem
Keywords: Cc:


Would it be possible to include a const-overloaded version of count() for associative containers in boost::bimaps? I had some code like this:

void CMyClass::func(size_t key) const {
       size_t num_elements=_member_map.count(key);

where _member_map was a std::map, and it worked fine. When I changed _member_map to a bimap, the equivalent code:

void CMyClass::func(size_t key) const {
       size_t num_elements=_member_map.left.count(key);

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.


Attachments (2)

07-const-count-overload.patch (883 bytes) - added by mlcreech@… 9 years ago.
associative_container_adaptor-count-const-fix.patch (543 bytes) - added by Gonzalo Matamala <gonmator@…> 8 years ago.

Download all attachments as: .zip

Change History (6)

Changed 9 years ago by mlcreech@…

Changed 8 years ago by Gonzalo Matamala <gonmator@…>

comment:1 Changed 8 years ago by Gonzalo Matamala <gonmator@…>

Version: Boost 1.36.0Boost 1.39.0

comment:2 Changed 8 years ago by Gonzalo Matamala <gonmator@…>

I think overloading count() is a wrong fix. The right fix is just adding const qualifier.

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]:

size_type count(const key_type& x) const;

Also, the bimap documentation ( declare count() member of

[multi]set_of as const:
template< class CompatibleKey >
size_type count(const key_type & x) const;

comment:3 Changed 8 years ago by Matias Capeletto

Status: newassigned

comment:4 Changed 8 years ago by Matias Capeletto

Resolution: fixed
Status: assignedclosed

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Matias Capeletto.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.