MythTV  master
Functions
ternarycompare.h File Reference
#include <type_traits>
#include <QChar>
Include dependency graph for ternarycompare.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename T >
std::enable_if_t< std::is_integral_v< T >, int > ternary_compare (const T a, const T b)
 balanced ternary (three way) comparison More...
 
int ternary_compare (const QChar a, const QChar b)
 

Function Documentation

◆ ternary_compare() [1/2]

template<typename T >
std::enable_if_t<std::is_integral_v<T>, int> ternary_compare ( const T  a,
const T  b 
)
inline

balanced ternary (three way) comparison

Parameters
aany integral type
bany integral type
Returns
-1, 0, or +1 if a is <, =, or > b, respectively This function is equivalent to C++20's operator <=> for integral types, returning an integer equivalent of std::strong_ordering.

Balance ternary comparison is useful for creating an ordering function for composite types, removing a double comparison of equality and a separate comparison for less than. Hopefully, the compiler will superoptimize this into a single, branchless comparison.

Definition at line 23 of file ternarycompare.h.

◆ ternary_compare() [2/2]

int ternary_compare ( const QChar  a,
const QChar  b 
)
inline

Definition at line 30 of file ternarycompare.h.