struct Comp { bool operator()(const std::pair &a, const std::pair &b) { if (a.first != b.first) { return a.first < b.first; } return a.second > b.second; } }; Comp comp_functor; std::sort(myVec.begin(), myVec.end(), comp_functor);