David Gruener
Hello,
how can one swap keys in an *ordered* index of a multi index container? Well, you cannot say something like:
blah.modify_key(blah.find(foo1), _1 = foo2); // from now index contains one element fewer, since // keys must be uniq blah.modify_key(blah.find(foo2), _1 = foo1);
I dind't found a way in the manual to swap directly.
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);
Providing a general key_swap facility is not as simple as it
might seem: swapping keys in an index can, in general, have
side effects on other indices --for instance, on those
indices that also depend on that particular key. Example:
multi_index_container<
int,
indexed_by<
ordered_unique
Swapping keys in index #0 has also an impact on index #1. Best regards, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo