I have an array of pointers to objects that are instances of a class from external code that I would rather not change.
I also have a vector of ints that was generated by calling a function on each object. So I have
A: [pointerToObj1, pointerToObj2, ... pointerToObjN]
And
B: [obj1Int, obj2Int, ..... objNInt]
How do I easily sort A such that it is sorted in by the values of B. I have boost available.
That is if B were
[3, 1, 2]
I want to sort A such that it is in the order
[pointerToObj2, pointerToObj3, pointerToObj1]
In javascript you could do this like
B.sort(function(a,b){return A[B.indexOf(a)] < A[B.indexOf(b)];});