compare function for upper_bound / lower_bound

前端 未结 4 481
粉色の甜心
粉色の甜心 2020-12-10 03:04

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

4条回答
  •  不知归路
    2020-12-10 03:43

    I think what you need is std::bind2nd(std::less(), x). But, of course, the operator< must be defined for MyClass.

    Edit: oh and I think you will need a constructor for MyClass that accepts only a float so that it can be implicitly converted. However, there might be a better way to do this.

提交回复
热议问题