Does following class breaks strict-weak-ordering (in comparison to regular std::less
(So ignoring edge case values such as Nan))
struct LessWithEpsilon
{
static constexpr double epsilon = some_value;
bool operator() (double lhs, double rhs) const
{
return lhs + epsilon < rhs;
}
};
LessWithEpsilon lessEps{};
From https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings
Similarly, from https://en.cppreference.com/w/cpp/named_req/Compare
With
{x, y, z} = {0, epsilon, 2 * epsilon}
, that rule is broken:!lessEps(x, y) && !lessEps(y, x) && !lessEps(y, z) && !lessEps(z, y)
butlessEps(x, z)
.equiv(x, y) == true and equiv(y, z) == true
butequiv(x, z) == false
(asx + epsilon < z
)So, that class breaks strict-weak-ordering.