Why will std::sort crash if the comparison function is not as operator

std::sort requires a sorter which satisfies the strict weak ordering rule, which is explained
here

So, your comparer says that a < bwhen a == b which doesn’t follow the strict weak ordering rule, it is possible that the algorithm will crash because it’ll enter in an infinite loop.

Leave a Comment