bool operator() (Foo* p1, Foo *p2) const { if (p1->x != p2->x) return p1->x < p2->x; return true; }
std::sort requires a sort function that creates a strictly weak order . This is not true. This is <= , which is not a strictly weak ordering. If lhs and rhs are equal, then comp(lhs, rhs) and comp(rhs, lhs) should return false.
Your function does not work. This way you get undefined behavior.
source share