#include <type_traits>
#include <QChar>
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) |
|
◆ 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
-
a | any integral type |
b | any 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 |