カスタムfind()関数を実装するためのクリーンな方法は何ですか?たとえば、operator ==がクラスXの検索で機能し、既存の値に近い変数の値と一致するようにします。
class X{
public:
double _a;
double _b;
double _c;
X(double a, double b, double c){
_a = a;
_b = b;
_c = c;
}
bool operator==(const X& other) const
{
if(fabs(other._a - _a) < 0.02) return true;
return false;
}
};
typedef X* ptrX;
std::vector<ptrX> vec;
ptrX t1 = new X(1,2,3);
vec.push_back(t1);
ptrX t = new X(1.01,2,3);
bool b = (find(vec.begin(),vec.end(),t) == vec.end()); //b should be false