lower_bound在 pair<int,int> 的向量上有效,upper_bound不起作用
lower_bound on a vector of pair<int,int> works, upper_bound does not
我有一个对的排序向量。为了找到lower_bound和upper_bound,我使用了:
bool cmp2(const pair<int,int> &p1, const int v)
{
if(p1.first<v)
return true;
else
return false;
}
auto it1 = lower_bound(V.begin(), V.end(), h, cmp2);
auto it2 = upper_bound(V.begin(), V.end(), h, cmp2);
这里 h 是一个整数。让我感兴趣的是,问题只存在于upper_bound。如果我注释掉upper_bound,我的程序就会成功构建。这可能是什么原因呢?
upper_bound
调用具有其他顺序的参数的比较器(首先搜索值,然后从它正在搜索的范围内搜索元素)。
所以你的比较器不起作用,因为它需要一对作为它的第一个参数和一个int
作为它的第二个参数。
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- int(c) 和 c-'0' 之间的区别。C++
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 是否可以从int转换为enum类类型
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- 'short int'持有的值溢出,但"自动"不会溢出?
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 调用'begin(int [n])'没有匹配函数
- 没有显式声明的int[]中的foreach
- 在c++中访问int到类对象的映射时出错
- 为什么我无法更改"set<set>"循环中的值<int>
- 长 长 int 不要 长 int 好
- C++程序在循环后给出奇怪的int值
- 如何计算数据类型的范围,例如int
- 如果"new int"返回"int*",那么为什么"new int[n]"不返回"int**"?
- "A reference may be bound only to an object",为什么"const int &ref = 3;"有效?