concurrency - Qt - calling mappedReduced -
i trying use qtconcurrent:mappedreduced, not simplicity of documentation description.i'm getting 4 errors code:
i'm using qt 5.9.1 msvc-2015
//....................... qmap<qstring,qstring> tesseractapi::analyze(qstringlist singledata); void joinmaps(qmap<qstring,qstring> map, const qmap<qstring,qstring> partial); //............. qmap<qstring, qstring> tesseractapi::analyzeall(qlist<qstringlist> data){ /*qfuture< qmap<qstring,qstring> > res*/; qfuture< qmap<qstring,qstring> > res = qtconcurrent::mappedreduced(data, tesseractapi::analyze, joinmaps); // tried adding '&' before functors res.waitforfinished(); qdebug()<<res.result(); return res.result(); }
the compiler errors:
c2780: 'qfuture<qtprivate::reduceresulttype<reducefunctor>::resulttype> qtconcurrent::mappedreduced(iterator,iterator,mapfunctor,reducefunctor,qtconcurrent::reduceoptions)': expects 5 arguments - 3 provided c2780: 'qfuture<t> qtconcurrent::mappedreduced(iterator,iterator,mapfunctor,reducefunctor,qtconcurrent::reduceoptions)': expects 5 arguments - 3 provided c2780: 'qfuture<t> qtconcurrent::mappedreduced(iterator,iterator,mapfunctor,reducefunctor,qtconcurrent::reduceoptions)': expects 5 arguments - 3 provided c2783: 'qfuture<t> qtconcurrent::mappedreduced(const sequence &,mapfunctor,reducefunctor,qtconcurrent::reduceoptions)': not deduce template argument 'resulttype'
i tried change data types, followed examples in documentation compile fines, couldn't find problem persist in code.
you're missing lot of &'s. first should pass data analyzeall()
via const ref, not copy:
qmap<qstring, qstring> tesseractapi::analyzeall(const qlist<qstringlist>& data){
next, should pass item mapping function via const ref, not copy. since it's class member function needs static, otherwise have know object call on, there's no such mappedreduced()
overload:
static qmap<qstring,qstring> tesseractapi::analyze(const qstringlist& singledata);
next, first parameter of reduce function needs reference, otherwise you'd modifying local copy, useless. thing reducing should passed via const ref, avoid unnecessary copy:
void joinmaps(qmap<qstring,qstring>& map, const qmap<qstring,qstring>& partial);
now should work. sake of stating intent it's nice explicitly add & function pointers, there's no confusion are:
qfuture< qmap<qstring,qstring> > res = qtconcurrent::mappedreduced(data, &tesseractapi::analyze, &joinmaps);
Comments
Post a Comment