lower_bound
возвращает самый нижний итератор (то есть положение в векторе) элемента, который на не меньше, чем третий параметр - здесь, queryweight
. Затем петля while
проходит через остальные элементы и, пока не достигнет элемента, у которого wight
больше или равно 60, добавляет их к вектору res
. Я предполагаю, что входной вектор w
отсортирован, иначе эта функция не имела бы особого смысла.
Строка за строкой:
// Declare a vector of pointers to 'weight' objects, called res.
// (I assume here that the "&" in the original question was a mistake.)
vector<weight *> res;
// Find the iterator that points to the lowest element in vector 'w'
// such that the element is >= queryweight.
vector<weight>::iterator it = lower_bound(w.begin(), w.end(), queryweight);
// From this element forwards until the end of vector 'w'
while(it != w.end()) {
// Get a pointer to the element.
weight *w = &(*it);
// If the 'wight' property of this element is >= 60, stop.
if(w->wight >= 60) break;
// Push the element onto the 'res' vector.
res.push_back(w);
// Move to the next element.
it++;
}