What is 3 way Comparator
-
a <=> b Compares the 2 variables(a,b) around it, and returns a value based on a and b
See example below
#include <compare>
#include <iostream>
int main()
{
int a = 2, b = 1;
auto res = a <=> b; //Since a is greater than b. res>1
/* res
a > b >1
a < b <1
a == b 0
*/
if (res > 0)
std::cout << "a greater than b";
else
std::cout << "a not greater than b";
}
# ./a.out
a greater than b