Rex Kerr wrote:
I'm trying to compare two vectors to ensure that their values are equal
within a tollerance (easy, std::equal with a binary predicate),
Here's what I have that doesn't work:
namespace
{
template <class T>
struct OutsideTollerance : public std::binary_function<T, T, T>
{
T operator() (T v1, T v2) const
{
return std::abs(v2 - v1) >= 2; // hardcoded for example
}
};
}
std::size_t num_mismatched = std::count_if( v1.begin(), v1.end(),
std::bind2nd(OutsideTollerance<BYTE>(), *(v2it++)) );
(variable names changed to protect the innocent)
Let's guess - originally it was OutsideTolerance ? ;)
Seriously - when using the STL, try to write proper functors. For any
kind of
"equal" operation, make sure that equal(a,b) and equal(a,c) implies
equal(b,c).
OutsideTolerance is not such an equal function. Now, your requirements
will
say you need OutsideTolerance to behave like this. That's life, it just
means
that using the STL here won't be trivial.
it's an unary functor in question...
[ comp.lang.c++.moderated. First time posters: Do this! ]