yat
0.14.5pre
|
Functor that behaves like std::less with the exception that it treats NaN as a number larger than infinity. More...
#include <yat/utility/stl_utility.h>
Public Member Functions | |
bool | operator() (T x, T y) const |
Functor that behaves like std::less with the exception that it treats NaN as a number larger than infinity.
This functor is useful when sorting ranges with NaNs. The problem with NaNs is that std::less always returns false
when one of the arguments is NaN. That together with the fact that std::sort only guarantees that an element i
is never less than previous element –i
. Therefore {10, NaN, 2} is sorted according to this definition, but most often it is desired that the 2 is located before the 10 in the range. Using this functor, less_nan, this can easily be achieved as std::sort(first, last, less_nan)
The default implementation uses std::isnan(T), which consequently must be supported.
There is a specialization less_nan<DataWeight>
|
inline |
true
if x is less than y. NaNs are treated as a number larger than infinity, which implies true
is returned if y is NaN and x is not.