Unexpected infinite loop when using std::list with custom comparator in C++20
I'm writing unit tests and I've hit a wall trying to I'm working with an infinite loop when attempting to sort a `std::list` using a custom comparator in C++20..... The comparator checks the values of the nodes in the list, but when I run the sort function, it seems to get exploring. Here's the relevant code snippet: ```cpp #include <iostream> #include <list> #include <algorithm> struct Node { int value; Node(int v) : value(v) {} }; bool customComparator(const Node& a, const Node& b) { // Intentionally flawed comparison to demonstrate an scenario return a.value < b.value; // This is correct, but I also have another condition } int main() { std::list<Node> myList = { Node(3), Node(1), Node(2) }; myList.sort(customComparator); for (const auto& node : myList) { std::cout << node.value << " "; } return 0; } ``` I suspect that the scenario might be related to the fact that `std::list::sort()` requires the comparator to establish a strict weak ordering, but my comparator is simple and doesn't account for equal values properly. Since I don't have any issues with the values themselves, I thought this wouldn't be a question. However, when I run the code, it enters an infinite loop when trying to sort the list. I've also tried using `std::vector` instead, and it works fine, indicating that the scenario might specifically be with `std::list`. I've checked other parts of the code, and I ensured that the list actually contains distinct integers at the time of sorting. Can someone guide me on what might be causing this infinite loop, and how I can properly implement the comparator for `std::list`? This is part of a larger service I'm building. I'd really appreciate any guidance on this. I'm on CentOS using the latest version of Cpp. What am I doing wrong?