Suppose I have some data stored in container unique_ptrs:
struct MyData {
int id;
data some_data;
};
std::vector<std::unique_ptr<MyData>> my_data_vec;
Order is important my_data_vec. Suppose now that I have another MyDatas ID vector:
std::vector<int> my_data_ids;
Now I want to reorder my_data_vecso that the elements are in the sequence indicated my_data_ids. (Remember that moving a unique_ptrrequires semantics c std::move().)
What is the most algorithmically efficient way to achieve this and which of the STL algorithms is well suited to achieve this? I do not see what std::sortwill be any help.
: O (n) ( ), ( ).