Search code examples
c++c++20comparison-operatorsspaceship-operator

Is there a std::less/std::greater for the spaceship operator?


All the basic comparisons (<, <=, ==, !=, >=, >) have an associated function object (std::less, std::less_equal, std::equal_to, std::not_equal_to, std::greater_equal, std::greater).

Does the spaceship operator <=> have a similar function object? If not, why was it not added to the standard library?


Solution

  • std::compare_three_way is the function object for three-way comparison (aka. spaceship operator).