我尝试使用 astd::set
以便在我的容器中拥有独特的元素。
因为我有 3D 对象:
Class Object3D{
private:
float x;
float y;
float z;
}
当 时,这些对象相等 (A.x==B.x && A.y==B.y && A.z==B.z)
。
在 std::set 实现中一个元素 A==B if (!(A < B) && !(B>A))
。
我的比较是不可能的......我试图重载==
运算符。
我在调用时选择了 set container 来比较值insert(a)
。std::vector v
我正在用和他的迭代器做类似的事情:
if(!(A).inVector()){
v.push_back(A);
}
和
bool inVector(){
for(itr = v.begin();itr != v.end();itr++){
if(this->x==(*itr)->x && this->y==(*itr)->y && this->z==(*itr)->z){
return true;
}
}
return false;
}
为每个对象(10000-100000)检查它的复杂性很高。
有人可以有一个想法吗?