Can I somehow overload any of std::multiset's operators (like you do with '()' to create a custom comapre function) so that when 2 elements in the multiset are swapped, so are another 2 elements from another vector linked to those?
I mean, I actually want to insert let's say elemetns {a,b,c,d,e} in the multiset, but I also want to keep track of their position inside the multiset, without having to use .find(). So I thought about creating another vector pos, where pos[k] is the position of element k in the multiset.
So, if I have this vector pos, I still must make the multiset when I insert an element in it, not to only put it in the right place in the multiset, but also change the pos[] of all elements swapped.
I don't exactly know how multiset changes/swaps it's element to sort them, but can I somehow override that so instead of:
swap(a,b);
I'll have something like.
swap(pos[a],pos[b]);
swap(a,b)
And if you have any other ideas of how could I keep track of an element's position inside a multiset, without using the .find() (which has O(N) complexity for equal elements) would be great!
EDIT
And also, I guess that I have to change something so that when I insert a new element (n) it will get the right initialization for pos[n]
, before any "swaps" are made.