Is there in the STL or in Boost a set of generic simple comparison functions?
The one I found are always requiring template parameters, and/or instantiation of a struct template.
I'm looking for something with a syntax like :
if ( is_equal(x,y) )
{
...
}
Which could be implemented as :
template <typename T>
bool is_equal(const T& x, const T& y)
{
return ( fabs(x - y) < Precision<T>::eps );
}
EDIT: I changed the operator to equal. (see comments below)
I don't know of any library that does it, perhaps because it is as simple as a one-liner or perhaps because it was forgotten...
As generality goes though, are you sure you'd like to set up the epsilon for one given type at a given value... throughout the application ? Personally I'd like to customize it depending on the operations I am doing (even though a default would be nice).
As for your operators, why not devising them yourself ?
The inequality and greater than methods can be trivially derived from this.
The additional parameter means that you may wish to specify another value for a given set of computations... an application-wide setting is too strict.
You could find some reasons of "complex" comparation logic here, in the documentation of boost test library.
From the comment of Marcelo Cantos:
I would imagine the implementation would be: