You could add 'operator <' to your object (if it doesn't have one) and use a map<object, int> to store the object->index mapping to be able to get the index of an object. If you have two indexes per object, you could either maintain two maps as you sort or make it a map<object, pair<int, int> >