我尝试按距离到特定点排序很多点。
所以,我决定使用std :: sort,但我找不到给出Comp函数第3个参数的方法。
我想象Python中的lambda函数就像lambda pnt1, pnt2: compare(pnt1, pnt2, myPoint)
一样,但我找不到它。
答案 0 :(得分:4)
类似的东西:
int distance(Point const&, Point const&); // Returns distance between points.
Point p{x, y};
std::vector<Point> points{...};
std::sort(points.begin(), points.end(), [p](Point const& a, Point const& b) {
return distance(a, p) < distance(b, p);
});