|
Boost Users : |
From: Daniel James (daniel_james_at_[hidden])
Date: 2008-03-20 07:51:26
On 20/03/2008, Abir Basak <abirbasak_at_[hidden]> wrote:
> 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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net