I have a QList and want to process all its elements in parallel. The problem is I need to pass an argument to my_function. The code below doesn’t allow for this.
QList<something> output = QtConcurrent::blockingMapped(
input,
my_function
);
I may use a distinct function for each set of parameters. I may use a global variable too. I may try to rewrite the build in QT function too. However, there should be a better solution. Any idea?
Assuming that the argument you want to pass to the function is independent of the items, you can create a functor that extends
std::unary_function<const something&,void>whose constructor takes the argument you want to pass to it. Then, use the functor where you would use the function. E.g.,