QtConcurrent::mappedReduced without mapped
Locked
Unsolved
Qt 6
-
I already asked this question here, but there is still no answer.
Consider the following code (Qt 6.0.3, C++17):const QVector<int> arr = {1, 2, 3, 4, 5}; auto future = QtConcurrent::mappedReduced<int>(arr, [](auto item) { return item; }, [](int& result, auto item) { result += item; });
As you can see the first lambda expression passed to
QtConcurrent::mappedReduced
looks unnecessary. That's why I want to find something likeQtConcurrent::reduced
in Qt 6. Or how can I refactor this code to use only 1 lambda expression? -
Hi and welcome to devnet,
You can use std::accumulate.
The goal of QtConcurrent mappedReduce is the apply an operation on all the items of container in a concurrent fashion and once done do the reduction.
In your case there's nothing to be done but the sum of the items so there's no need for mappedReduce.