开发者

Is it possible for std::sort to lead to a bug? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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?


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).


If your comparison function/object doesn't follow a strict weak ordering, or the thing you're sorting contains pointers that are no longer valid, either of those could cause it to break.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜