Boost logo

Boost :

Subject: [boost] Const-overload for bimap associative_container_adaptor::count()
From: Matthew L. Creech (mlcreech_at_[hidden])
Date: 2008-10-18 22:44:55


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

-- 
Matthew L. Creech



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk