A
Alf P. Steinbach
* Greg Herlihy:
For a std::map the 'less' operation must define a strict weak ordering.
"Strict" means that !(a op a) holds for all a. This is true of the
'less' above.
Exactly what "weak" means I'm not sure, but the standard's requirement
(in §25.3/4) is that 'less' should define an equivalence relation, via
bool eq(a,b) { return !less(a,b) && !less(b,a); }
which must be transitive,
eq(a,b) && eq(b,c) implies eq(a,c)
This requirement is not met for the 'less' above.
You can have (a,b) such that their difference is less than EPSILON, and
(b,c) such that their difference is less than EPSILON, but such that the
difference for (a,c) is greater than EPSILON.
There is no undefined behavior. The less() function does produce a
total ordering:
For any a, b, and c such that less(a, b) returns true and less(b, c)
returns true, then it is the case that less( a, c) also returns true.
For a std::map the 'less' operation must define a strict weak ordering.
"Strict" means that !(a op a) holds for all a. This is true of the
'less' above.
Exactly what "weak" means I'm not sure, but the standard's requirement
(in §25.3/4) is that 'less' should define an equivalence relation, via
bool eq(a,b) { return !less(a,b) && !less(b,a); }
which must be transitive,
eq(a,b) && eq(b,c) implies eq(a,c)
This requirement is not met for the 'less' above.
You can have (a,b) such that their difference is less than EPSILON, and
(b,c) such that their difference is less than EPSILON, but such that the
difference for (a,c) is greater than EPSILON.