簡體   English   中英

對向量上的lower_bound <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作為它的第二個參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM