0

I have an std::vector of pairs of defined as the following structure:

template<typename Iterator>
struct Pair{
double a;
Iterator iterator;
};

1 Answers1

2

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>&.

Smeeheey
  • 9,906
  • 23
  • 39