Hello, I've been trying to get QtConcurrent::blockingMappedReduced to run using a couple of lambda's and keep running into a compile issue which I can't get to the bottom of. I've cut it right back and am currently using Qt's own example code converted into lambda's and getting the same error. So here it is:
typedef QMap<QString, int> WordCount;
void ClassName::ProcessStuff() {
auto wordMapFn
= [&](const QString &file
) -> WordCount
{ WordCount wordCount;
while (textStream.atEnd() == false)
foreach
(QString word, textStream.
readLine().
split(" ")) wordCount[word] += 1;
return wordCount;
};
auto wordReduceFn = [&](WordCount &result, const WordCount &w) {
QMapIterator<QString, int> i(w);
while (i.hasNext()) {
i.next();
result[i.key()] += i.value();
}
};
WordCount total = QtConcurrent::blockingMappedReduced(files.begin(), files.end(), wordMapFn, wordReduceFn);
}
typedef QMap<QString, int> WordCount;
void ClassName::ProcessStuff() {
auto wordMapFn = [&](const QString &file) -> WordCount {
QFile f(file);
f.open(QIODevice::ReadOnly);
QTextStream textStream(&f);
WordCount wordCount;
while (textStream.atEnd() == false)
foreach (QString word, textStream.readLine().split(" "))
wordCount[word] += 1;
return wordCount;
};
auto wordReduceFn = [&](WordCount &result, const WordCount &w) {
QMapIterator<QString, int> i(w);
while (i.hasNext()) {
i.next();
result[i.key()] += i.value();
}
};
QStringList files;
WordCount total = QtConcurrent::blockingMappedReduced(files.begin(), files.end(), wordMapFn, wordReduceFn);
}
To copy to clipboard, switch view to plain text mode
Compiling this in VS2012 with Qt5.0.2 produces the following error:
1>Implementation\ImportExport\OpcExporter.cpp(250): error C2893: Failed to specialize function template 'QtPrivate::ReduceResultType<ReduceFunctor>::ResultType QtConcurrent::blockingMappedReduced(Iterator,Iterator,MapFunctor,ReduceFunctor,QtConcurrent::ReduceOptions)'
1> With the following template arguments:
1> 'QList<T>::iterator'
1> with
1> [
1> ]
1> 'ImportExport::OpcExporter::CreateProjectChildAndAttachedParts::<lambda_34d77ea4bb1263c3043c2eae1f2efb26>'
1> 'ImportExport::OpcExporter::CreateProjectChildAndAttachedParts::<lambda_0b977c9c36b310423ccf2f5f1c540fb3>'
1>Implementation\ImportExport\OpcExporter.cpp(250): error C2783: 'ResultType QtConcurrent::blockingMappedReduced(Iterator,Iterator,MapFunctor,ReduceFunctor,QtConcurrent::ReduceOptions)' : could not deduce template argument for 'ResultType'
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtconcurrent\qtconcurrentmap.h(237) : see declaration of 'QtConcurrent::blockingMappedReduced'
1>Implementation\ImportExport\OpcExporter.cpp(250): error C2893: Failed to specialize function template 'QtPrivate::ReduceResultType<ReduceFunctor>::ResultType QtConcurrent::blockingMappedReduced(const Sequence &,MapFunctor,ReduceFunctor,QtConcurrent::ReduceOptions)'
1> With the following template arguments:
1> 'QList<T>::iterator'
1> with
1> [
1> ]
1> 'ImportExport::OpcExporter::CreateProjectChildAndAttachedParts::<lambda_34d77ea4bb1263c3043c2eae1f2efb26>'
1> 'QList<T>::iterator'
1> with
1> [
1> ]
1>Implementation\ImportExport\OpcExporter.cpp(250): error C2783: 'ResultType QtConcurrent::blockingMappedReduced(const Sequence &,MapFunctor,ReduceFunctor,QtConcurrent::ReduceOptions)' : could not deduce template argument for 'ResultType'
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtconcurrent\qtconcurrentmap.h(208) : see declaration of 'QtConcurrent::blockingMappedReduced'
1>
1>Build FAILED.
1>Implementation\ImportExport\OpcExporter.cpp(250): error C2893: Failed to specialize function template 'QtPrivate::ReduceResultType<ReduceFunctor>::ResultType QtConcurrent::blockingMappedReduced(Iterator,Iterator,MapFunctor,ReduceFunctor,QtConcurrent::ReduceOptions)'
1> With the following template arguments:
1> 'QList<T>::iterator'
1> with
1> [
1> T=QString
1> ]
1> 'ImportExport::OpcExporter::CreateProjectChildAndAttachedParts::<lambda_34d77ea4bb1263c3043c2eae1f2efb26>'
1> 'ImportExport::OpcExporter::CreateProjectChildAndAttachedParts::<lambda_0b977c9c36b310423ccf2f5f1c540fb3>'
1>Implementation\ImportExport\OpcExporter.cpp(250): error C2783: 'ResultType QtConcurrent::blockingMappedReduced(Iterator,Iterator,MapFunctor,ReduceFunctor,QtConcurrent::ReduceOptions)' : could not deduce template argument for 'ResultType'
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtconcurrent\qtconcurrentmap.h(237) : see declaration of 'QtConcurrent::blockingMappedReduced'
1>Implementation\ImportExport\OpcExporter.cpp(250): error C2893: Failed to specialize function template 'QtPrivate::ReduceResultType<ReduceFunctor>::ResultType QtConcurrent::blockingMappedReduced(const Sequence &,MapFunctor,ReduceFunctor,QtConcurrent::ReduceOptions)'
1> With the following template arguments:
1> 'QList<T>::iterator'
1> with
1> [
1> T=QString
1> ]
1> 'ImportExport::OpcExporter::CreateProjectChildAndAttachedParts::<lambda_34d77ea4bb1263c3043c2eae1f2efb26>'
1> 'QList<T>::iterator'
1> with
1> [
1> T=QString
1> ]
1>Implementation\ImportExport\OpcExporter.cpp(250): error C2783: 'ResultType QtConcurrent::blockingMappedReduced(const Sequence &,MapFunctor,ReduceFunctor,QtConcurrent::ReduceOptions)' : could not deduce template argument for 'ResultType'
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtconcurrent\qtconcurrentmap.h(208) : see declaration of 'QtConcurrent::blockingMappedReduced'
1>
1>Build FAILED.
To copy to clipboard, switch view to plain text mode
Any help much appreciated.
Bookmarks