
"Alberto Ganesh Barbati" <abarbati@iaanus.com> wrote> template <typename T>
struct compare_absolute_error : std::binary_function<T, T, bool> { T eps; compare_absolute_error(T eps_) : eps(eps_) {} bool operator()(T x, T y) const { return abs(x - y) < eps; } };
BTW An alternate signature for the function: template <typename T> struct compare_absolute_error /*not derived from binary_function!*/ { T eps; compare_absolute_error(T eps_) : eps(eps_) {} //Signature as thus to prevent too many conversions template <typename T1, typename T2> bool operator()(T1 const & x, T2 const & y) const { return abs(x - y) < eps; } }; // ............. possible useage : compare_absolute_error<int> comp(1); int pixel_x =100; float current_pos_x = 100.5; bool grabbed = comp(current_pos_x, pixel_x); regards Andy Little