我正在尝试在一个vector<pair<int,int>>
上使用upper_bound
,就像这样:
vector<pair<int,int>> data;
auto up = upper_bound(data.begin(), data.end(), 0);
我使用VS2012时遇到了以下错误:
error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const int'
为什么它要将一个
const int
与一个 pair<int,int>
进行比较?我尝试编写自己的比较函数,但这并没有改变任何东西。如果我这样做,编译器会尝试将 pair<int,int>
转换为 const int
。
upper_bound(data.begin(), data.end(), 0);
,最后一个参数显然是一个数字。请展示你的比较器。 - Bartek Banachewicz