I'm trying to find bounds in the part of vector from next iterator position to the end of the vector.
The code is:
#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;
}
Unfortunately, std::lower_bound(i+1, v.end(), -10-*i) triggers compilation error which I cannot understand.
What is the problem with the statement above and how to properly call std::lower_bound with i+1 iterator?
Aucun commentaire:
Enregistrer un commentaire