David Gruener ha escrito:
Joaquin M Lopez Munoz wrote:
There's no particular provision for swapping keys. You could do something like:
blah.modify_key(blah.find(foo1), _1 = unused_value); blah.modify_key(blah.find(foo2), _1 = foo1); blah.modify_key(blah.find(unused_value), _1 = foo2);
Well, i did something like this (in my case unused_value is INT_MIN). But i really dont find that a clean solution. I think the container must not assume that i always have something like an "unused" value in the particular domain, it seems easy for int, but that might not be true for other types.
I totally agree with you; it's an ugly workaround (but at least is more than you can do with an std::container, since you retain iterator and reference stability.)
Providing a general key_swap facility is not as simple as it might seem
Thats what I expected. Not simple, but don't you think thats possible, do you?
It's possible, at the expense of fattening the internal implementation of all indices :(
I think we need a swap() for values too, because a value might be used as a uniq key in another index. IMHO such a swap method is valuable.
From the point of view of the internal implementation, a value swap is entirely equivalent to a key swap (same relationship as between modify and modify_key, internally the implementation is the same.) The practical usefulness of a value swap AFAICS is limited, though, since it only would have any important effect on sequenced indices, and for those you can use relocate().
In any case, I'm writing this down into my list of things to consider. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo