struct compar {
bool operator()(const vector<int>& a,
const vector<int>& b) const {
return a[1] < b[1];
}
};
...
auto it = lower_bound(events.begin(), events.end(), {0, events[i][0]}, compar());
这段代码给了我一个关于 {0, events[i][0]} 的错误:
/bits/stl_algo.h:2022:5: note: candidate template ignored: couldn't infer template argument '_Tp'
lower_bound(_ForwardIterator __first, _ForwardIterator __last,
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/algorithmfwd.h:353:5: note: candidate function template not viable: requires 3 arguments, but 4 were provided
lower_bound(_FIter, _FIter, const _Tp&);
^
1 error generated.
但是当我将它明确定义为向量时,它会按需要工作。
vector<int> point = {0, events[i][0]};
auto it = lower_bound(events.begin(), events.end(), point, compar());
有人可以解释为什么吗?