compare function for upper_bound / lower_bound

Posted by Martin Beckett on Stack Overflow See other posts from Stack Overflow or by Martin Beckett
Published on 2009-05-15T16:12:49Z Indexed on 2010/03/24 18:23 UTC
Read the original article Hit count: 328

Filed under:
|
|

I want to find the first item in a sorted vector that has a field less than some value x.
I need to supply a compare function that compares 'x' with the internal value in MyClass but I can't work out the function declaration.
Can't I simply overload '<' but how do I do this when the args are '&MyClass' and 'float' ?

 float x;
 std::vector< MyClass >::iterator last = std::upper_bound(myClass.begin(),myClass.end(),x);

© Stack Overflow or respective owner

Related posts about c++

Related posts about stl