I have a vector
of shared_ptrs
of my class Person
, which looks like:
QVector <std::shared_ptr<const Person>> vecOfPeople;
One of Person's field is age
and I want to calculate with QtConcurrent::filteredReduced
for example how many there are people over 50
and I find it very difficult to understand how to do it. I have a bool
returning function isOver50
as:
bool isOver50(std::shared_ptr<const Person> &person)
{
return person->getAge() > 50;
}
And if I understand good, there should be also a reduction
function, which at my code looks like:
void reduction(int &result, std::shared_ptr<const Person> &person)
{
result++;
}
And finally, code with filteredReduced
as:
QFuture<int> futureOver50 = QtConcurrent::filteredReduced(vecOfPeople, isOver50, reduction);
futureOver50.waitForFinished();
qDebug() << futureOver50.result();
This doesn't compile, my bet is there's something wrong in reduction
function, but I have no idea what it is.