The STL overs a variety of functions to find elements in container classes. Are there similar functions in for Qt 5.5 container classes e.g. QList
or QVector
?
Especially, I'm looking for an equivalent one-liner i.e. std::find_if
using Qt containers and Qt algorithms:
int main(int arg, char** args) {
std::vector<int> c = { 2,3,4,6,6,15 };
if (std::find_if(c.begin(), c.end(), [](const int& value) { return value % 5 == 0; }) != c.end()) {
std::cout << "At least one element divisible by 5." << std::endl;
} else {
std::cout << "No element is divisible by 5." << std::endl;
}
return 0;
}
The predicate of an element being divisible by 5 should be just serve as an example.
Does the Qt Framework provides such nice algorithms?
std::find_if
on Qt containers such asQVector
, it works fine. There isQVector::indexOf
and some others, I didn't find afind_if
version.QVector
andstd::vector
.std::vector
? You can callstd::find_if
directly with aQVector
.QVector
interface is compatible with theSTL
? That is really ingenious.