4 ms·
This had bit me in the past with std::sort that made seemingly benign code randomly crash a live service, cppreference has a list of all the standard facilities
by diath 1y ago
This had bit me in the past with std::sort that made seemingly benign code randomly crash a live service, cppreference has a list of all the standard facilities that need to meet these requirements: https://en.cppreference.com/w/cpp/named_req/Compare.html https://en.cppreference.com/w/cpp/named_req/Compare.html
- deleted 1y ago[deleted]
- monkeyelite 1y agowhat did you try to use as a comparison function?
- diath 1y agoThis was the original sort function (it was meant to force "last" to be first on the list after the sort which obviously violated the requirement): std::sort(entries.begin(), entries.end(), [&last] (const auto &a, const auto &b) { if (last && last->getID() == a.id) { return true; } return a.time < b.time; });
- monkeyelite 1y agoInteresting… I’m sure you resolved this. But the textbook solution is: 1. std::find last 2. std::iter_swap(first, found) 3. std::sort(front + 1, back)