Is there a better way to create a sorted array of member variable from a sorted array of custom(ie user defined) objects in C++?
Example -
class People{
public:
unsigned int birth_year;
};
Lets say we have an array of std::vector<People>
and we want to get std::vector<unsigned int>
sorted by birth year.
We can use one of the many ways to sort the custom object mentioned in this link - Sorting a vector of custom objects
Now, if we need to get the sorted birth year vector, we will have to iterate through the sorted People vector and push it on to a new vector of unsigned int.
Is there a faster way to do this(using memory offsets or such)? OR is there a feature in C++11 which we can leverage for this?
Aucun commentaire:
Enregistrer un commentaire