У меня есть простая структура, которую я использую в качестве ключа в std :: map
struct PpointKey{
unsigned int xp,yp; //pixel coordinates
unsigned int side;
PpointKey(unsigned xp,unsigned yp,unsigned side=5):xp(xp),yp(yp),side(side)
{}
bool operator==(const PpointKey& other) const{
const unsigned int x = other.xp;
const unsigned int y = other.yp;
return ((x>=xp && x<=xp+side) && (y>=yp && y<=yp+side));
}
bool operator<(const PpointKey& other) const{
const unsigned int x = other.xp;
const unsigned int y = other.yp;
const unsigned other_distance_2 = x*x + y*y;
const unsigned this_distance_2 = this->xp*this->xp + this->yp * this->yp;
return this_distance_2 < other_distance_2;
}
};
Чего я хотел бы добиться, так это использовать find () для доступа к карте с помощьюключ с атрибутами xp, yp на расстоянии side
.Другими словами, если у меня есть кортеж (x, y), я бы хотел найти внутри карты первый PpointKey, который удовлетворяет условию внутри оператора == function
return ((x>=xp && x<=xp+side) && (y>=yp && y<=yp+side));
Возможно ли это с помощью find?Я получаю map.end (), поэтому я хотел бы проверить, использует ли функция find () оператор ==.Может быть, алгоритм поиска будет лучше?
Заранее спасибо.