我试图在向量的一部分中找到从下一个迭代器位置到向量末尾的边界.
代码是:
#include <algorithm>
#include <vector>
#include <iostream>
int
main()
{
typedef std::vector<int> Vector;
Vector v;
v.push_back(3);
v.push_back(7);
v.push_back(15);
v.push_back(21);
std::sort(v.begin(), v.end());
for (Vector::const_iterator i = v.begin(); i != v.end(); ++i) {
Vector::const_iterator low = std::lower_bound(i+1, v.end(), -10-*i);
Vector::const_iterator high = std::upper_bound(i+1, v.end(), 10-*i);
for (Vector::const_iterator j = low; j != high; ++j) {
std::cout << *i << "~" << *j << std::endl;
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,std::lower_bound(i+1, v.end(), -10-*i)触发编译错误,我无法理解:
c++ -O3 -ggdb -std=c++11 -W -Wall -pedantic …Run Code Online (Sandbox Code Playgroud)