I have an std::vector of pairs of defined as the following structure:
template<typename Iterator>
struct Pair{
double a;
Iterator iterator;
};
I have an std::vector of pairs of defined as the following structure:
template<typename Iterator>
struct Pair{
double a;
Iterator iterator;
};
You can give a custom comparator to sort, as a lambda:
std::sort(vec.begin(), vec.end(), [](const auto& lhs, const auto& rhs) {return lhs.a < rhs.a;});
Note: the above is C++14 syntax. If you wish it to be compliant with C++11, you simply change the const auto&
in the above to the const &
actual type of the vector, e.g. const Pair<MyIter>&
.