quertion about std::sort cmp function

When I define a vector<int> contains one hundred 0s and sort with the code below, an exception "invalid comparator" throws.

1
2
3
4
5
vector<int> v(100, 0);
sort(v.begin(), v.end(), [](const int& a, const int& b)
	{
		return a >= b;
	});


Howerver, if I use " return a > b ", it will execute well.
Thanks very much if some could help me.
Last edited on
The comparator should return true if the first argument should be ordered before the second argument otherwise it should return false. That means equal elements (and comparing an element with itself) should return false which is why >= is wrong.
Last edited on
Thanks a lot. Your answer really benefits me.
Topic archived. No new replies allowed.