我有一对std :: vector对被定义为以下结构:
template<typename Iterator>
struct Pair{
double a;
Iterator iterator;
};
答案 0 :(得分:2)
您可以将自定义比较器排序为lambda:
std::sort(vec.begin(), vec.end(), [](const auto& lhs, const auto& rhs) {return lhs.a < rhs.a;});
注意:以上是C ++ 14语法。如果您希望它符合C ++ 11,您只需将上面的const auto&
更改为向量的const &
实际类型,例如const Pair<MyIter>&
。