I was trying to find how many element are less than a certain X in a multiset by using:
mset.lower_bound(X) - mset.begin()
But it didn't work. Any workarounds?
You may use:
std::distance(mset.begin(), mset.lower_bound(X));
To make it robust, use:
size_t count = 0;
auto found = mset.lower_bound(X);
if ( found != mset.end() )
{
count = std::distance(mset.begin(), found);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With