0

How to check if the upper_bound function on a sorted vector is pointing to end o...

 1 year ago
source link: http://codeforces.com/blog/entry/108858
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to check if the upper_bound function on a sorted vector is pointing to end of the vector?

If all the values in vector are less than or equal to M then "i" will point to v.end().

auto i = upper_bound(v.begin(), v.end(), M)- v.begin();

Now if I want to do certain action if "i" points to the end of vector, I tried

if(i == v.end()){ // Code }

But it doesn't work, throwing error: no match for ‘operator==’ (operand types are ‘long int’ and ‘std::vector::iterator’)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK