yat  0.18pre
Public Member Functions | List of all members
theplu::yat::utility::less_nan< T > Struct Template Reference

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>

Inheritance diagram for theplu::yat::utility::less_nan< T >:

Public Member Functions

bool operator() (T x, T y) const
 

Detailed Description

template<typename T>
struct theplu::yat::utility::less_nan< T >

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>

Since
New in yat 0.6

Member Function Documentation

template<typename T>
bool theplu::yat::utility::less_nan< T >::operator() ( x,
y 
) const
inline
Returns
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.

The documentation for this struct was generated from the following file:

Generated on Sun Sep 27 2020 02:26:14 for yat by  doxygen 1.8.11