MythTV  master
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.


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 

balanced ternary (three way) comparison

aany integral type
bany integral type
-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 

Definition at line 30 of file ternarycompare.h.