My Question is related to this as I solved the problem, I wrote my own sorting algorithm (a simple insertion sort), and it works. I am quite surprised by this as I thought that the standard library is well-tested. Are there any known special cases in which std::sort might mess up?
My Question is related to this as I solved the problem, I wrote my
Share
No, it’s highly unlikely that there are any known bugs in any of the common C++ standard library implementations of
std::sort. It’s rigorously tested.If you see a crash or incorrect results, it’s almost certainly because you didn’t adhere to the contract: either you passed in invalid arguments, or your comparator does not obey the requirements for a strict weak ordering (irreflexivity, asymmetry, transitivity, and transitivity of equivalence).