Re: [boost] [multi_index] key swap status

Joaquín Mª López Muñoz wrote:
c.insert(std::make_pair(0,1)); c.insert(std::make_pair(1,0)); c.insert(std::make_pair(1,1)); c.swap_keys(c.begin(),++c.begin()); // would yield a duplicate element (1,1)
... it implies that a possible outcome of swap_keys() is that both elements get deleted
That`s what i would expect here. :] Now, why is this surprising? Consider the following snippet: multi_index_container<int> c; // default "set"-like c.insert(1); c.insert(2); c.modify_key(--c.end(), _1 = 1); Isn`t it "surprising" in the same way, that c.size() == 1? ;-)
On another issue, you might be interested to know that the problem you brought forward in
http://lists.boost.org/Archives/boost/2005/02/80589.php
has been solved in 1.34
Nice! Best Regards, David. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.

gruenedd@idmt.fraunhofer.de ha escrito:
Joaquín Mª López Muñoz wrote:
c.insert(std::make_pair(0,1)); c.insert(std::make_pair(1,0)); c.insert(std::make_pair(1,1)); c.swap_keys(c.begin(),++c.begin()); // would yield a duplicate element (1,1)
... it implies that a possible outcome of swap_keys() is that both elements get deleted
That`s what i would expect here. :] Now, why is this surprising? Consider the following snippet:
multi_index_container<int> c; // default "set"-like c.insert(1); c.insert(2); c.modify_key(--c.end(), _1 = 1);
Isn`t it "surprising" in the same way, that c.size() == 1? ;-)
Yep, well. I don't know, swap_keys's very name seems to indicate it'll follow std::swap semantics, which certainly doesn't have elimination of swapped elements as a possibility. Anyway, the other two reasons I gave for not providing this feature have more weight in my decision. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Quoting Joaquín Mª López Muñoz <joaquin@tid.es>:
Anyway, the other two reasons I gave for not providing this feature have more weight in my decision.
And they are valid. :] Nevertheless, as Joseph stated, multi_index is really useful. David. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
participants (2)
-
gruenedd@idmt.fraunhofer.de
-
Joaquín Mª López Muñoz