The Comparator That Crashes
The C++ standard requires comp to induce a strict weak ordering, where strict means the relation is irreflexive: !comp(x, x) must hold for every x. A developer writes:
std::sort(tasks.begin(), tasks.end(),
[](const Task &a, const Task &b) { return a.priority <= b.priority; });
reasoning that <= is "the same order, just including ties". The code passes on small test data and later crashes in production. What is the correct account?
Sign in to answer questions and track your progress
Sign In