#include <yat/utility/stl_utility.h>
Public Member Functions | |
bool | operator() (T x, T y) const |
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>
bool theplu::yat::utility::less_nan< T >::operator() | ( | T | x, | |
T | y | |||
) | const [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.