I have std::set<std::pair<float,float>> which represents points on map ( 2d , x and y value) and I have one point with values x1 and y1. How to sort set in ascending order by distance from point ( x1,y1) ?
I have std::set<std::pair<float,float>> which represents points on map ( 2d , x and y
Share
std::set is an ordered container, and ordering happens upon insertion, depending on a sorting criteria which can be specified with a second template argument. So use a
setwith a predicate which returns true or false based on the distance to the reference point.It is enough to compare the distance squared, thus avoiding calls to
std::sqrt.