
On 20/03/2008, Abir Basak
Hi while i am using boost unordered_set , and insert a new key value pair, it returns the iterator as a const one. In fact when i looked at the code, the iterator is a typedef to implementation::const_iterator ... so there is no way to gen an mutable iterator from the set, including begin() and end() is it a standard behavior or i am missing something ?
It's standard behaviour. The keys in unordered containers are const, because if you change it, it could change the position that the element should be in. And since the elements in unordered_sets unordered_multisets are just the keys, they are const as well. The situation is the same with std::set. There has been some debate on this in the past. The typical solution is to use an unordered_map, where the key is constant but the mapped type is not. Boost.Bimap, Boost.Multindex and Boost.Intrusive might offer alternative ways of dealing with this, but I don't know them well enough to say. Daniel