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

Revision en2, by vedant-z, 2022-11-08 12:07:01

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’)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English vedant-z 2022-11-08 12:07:01 53
en1 English vedant-z 2022-11-08 11:39:01 555 Initial revision (published)