나는 내가이 표준의 핵심 :: 내가 달성하고자하는 어떤표준 : :지도 : : (
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;
}
};
가 찾기를 사용하는 맵으로 사용하고 간단한 구조체가) (발견)를 사용하여 side
거리 내에 xp, yp 속성이있는 키를 사용하여 맵에 액세스하십시오. I는 (x, y)는 튜플이 있다면 즉, I지도 내부 찾을 사용이 가능하다 연산자 == 함수
return ((x>=xp && x<=xp+side) && (y>=yp && y<=yp+side));
내부의 조건을 만족 제 PpointKey을 찾을 하시겠습니까? 나는 map.end()를 얻고있다. find() 함수가 연산자 ==를 사용하는지 확인하고 싶다. 어쩌면 검색 알고리즘이 더 좋을까요?
미리 감사드립니다.
'std :: map'은'operator <'만을 사용한다는 것을 명심하십시오. 두 키가 다른 키보다 작지 않으면 두 개의 키가 같은 것으로 간주됩니다. –