Opened 14 years ago
Closed 13 years ago
#2484 closed Patches (fixed)
Const-overload needed for bimap associative_container_adaptor::count()
Reported by: | Owned by: | Matias Capeletto | |
---|---|---|---|
Milestone: | Boost 1.38.0 | Component: | bimap |
Version: | Boost 1.39.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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.
Thanks
Attachments (2)
Change History (6)
by , 14 years ago
Attachment: | 07-const-count-overload.patch added |
---|
by , 13 years ago
Attachment: | associative_container_adaptor-count-const-fix.patch added |
---|
comment:1 by , 13 years ago
Version: | Boost 1.36.0 → Boost 1.39.0 |
---|
comment:2 by , 13 years ago
comment:3 by , 13 years ago
Status: | new → assigned |
---|
comment:4 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
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]:
Also, the bimap documentation (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) declare count() member of