Reputation:
I have a set<int>
and I want to see how many elements in it are less than x. (x is also int)
What should i do?
Upvotes: 12
Views: 12461
Reputation: 477040
Use lower_bound
to compute std::distance(s.begin(), s.lower_bound(x))
. (If x
is a key, this counts the number of elements strictly before x
.)
Upvotes: 20