Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The range of the return value is not the issue - the comparison function [0] for std::sort returns a bool and not a tristate anyway.

What gp probably messed up is the one of the guarantees of a strict weak ordering:

- Irreflexivity: comp(a, a) == false for all a

- Transitivity: if comp(a, b) == true and comp(b, c) == true then comp(a, c) == true

- Asymmetry: if comp(a, b) == true then comp(b, a) == false

std::sort can assume that all these requirements are true and does not have to care about what happens if they don't.

[0] https://en.cppreference.com/w/cpp/named_req/Compare



Thanks very much for this :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: