invalid operator < while sorting std::list

后端 未结 1 973
Happy的楠姐
Happy的楠姐 2020-12-15 19:14

I have a std::list graph edges and i want to sort the edges based on their destination outdegree and then their indegree. But i am getting getting exception of invalid oper

相关标签:
1条回答
  • 2020-12-15 19:44

    Your comparator returns true when both relevant fields are equal. This is invalid, so it may well be what the sort implementation has detected via assert.

    You're supposed to pass a "less than" predicate to sort: formally a "strict weak order". Anything else is undefined behavior. It seems in this case you got lucky, and the implementation detects that it has got into an impossible situation due to inconsistent comparisons.

    0 讨论(0)
提交回复
热议问题