[Development] Using lambda in QtConcurrent::map
Stephen Chu
stephen at ju-ju.com
Sat Sep 29 20:17:49 CEST 2012
I am having problem using lambda in QtConcurrent::map() function. The
following code:
#include <QtConcurrent>
int foo(int i) { return i+1; }
void moo(QList<int> list)
{
QtConcurrent::mapped(list, [](int i){ return foo(i); });
}
produces errors below with Clang 3.1. Is lambda supported in map()? Or
do I need to wrap the lambda in a std::function?
clang++ -c -pipe -mmacosx-version-min=10.6 -arch i386 -stdlib=libc++
-std=c++11 -g -gdwarf-2 -Wall -W -fPIE -DQT_PRINTSUPPORT_LIB
-DQT_WIDGETS_LIB -DQT_CONCURRENT_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB
-DQT_CORE_LIB -I/Qt/5.0/qtbase/mkspecs/macx-clang-libc++-32
-I../../Dropbox/Client2012 -I../../Dropbox/Client2012/DataTable
-I../../Dropbox/Client2012/Tools -I../../Dropbox/Client2012/OUTViewer
-I../../Dropbox/Client2012/OUTViewer/lcms
-I../../Dropbox/Client2012/OUTViewer/lcms/lcms2-2.4/include
-I../../Dropbox/Client2012 -I/Qt/5.0/qtbase/include
-I/Qt/5.0/qtbase/include/QtPrintSupport
-I/Qt/5.0/qtbase/include/QtWidgets -I/Qt/5.0/qtbase/include/QtConcurrent
-I/Qt/5.0/qtbase/include/QtNetwork -I/Qt/5.0/qtbase/include/QtGui
-I/Qt/5.0/qtbase/include/QtCore -I.
-I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers
-I/System/Library/Frameworks/AGL.framework/Headers -I.
-F/Qt/5.0/qtbase/lib -o moo.o ../../Dropbox/Client2012/Tools/moo.cpp
In file included from ../../Dropbox/Client2012/Tools/moo.cpp:1:
In file included from /Qt/5.0/qtbase/include/QtConcurrent/QtConcurrent:11:
In file included from
/Qt/5.0/qtbase/include/QtConcurrent/qtconcurrentfilter.h:1:
In file included from
/Qt/5.0/qtbase/include/QtConcurrent/../../src/concurrent/qtconcurrentfilter.h:49:
In file included from
/Qt/5.0/qtbase/include/QtConcurrent/qtconcurrentfilterkernel.h:1:
In file included from
/Qt/5.0/qtbase/include/QtConcurrent/../../src/concurrent/qtconcurrentfilterkernel.h:50:
In file included from
/Qt/5.0/qtbase/include/QtConcurrent/qtconcurrentmapkernel.h:1:
/Qt/5.0/qtbase/include/QtConcurrent/../../src/concurrent/qtconcurrentmapkernel.h:166:78:
error: no type named 'result_type' in '<lambda at
../../Dropbox/Client2012/Tools/moo.cpp:7:29>'
class MappedEachKernel : public IterateKernel<Iterator, typename
MapFunctor::result_type>
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/Qt/5.0/qtbase/include/QtConcurrent/../../src/concurrent/qtconcurrentmapkernel.h:214:33:
note: in instantiation of template class
'QtConcurrent::MappedEachKernel<QList<int>::const_iterator, <lambda at
../../Dropbox/Client2012/Tools/moo.cpp:7:29> >' requested here
struct SequenceHolder1 : public Base
^
/Qt/5.0/qtbase/include/QtConcurrent/../../src/concurrent/qtconcurrentmapkernel.h:238:34:
note: in instantiation of template class
'QtConcurrent::SequenceHolder1<QList<int>,
QtConcurrent::MappedEachKernel<QList<int>::const_iterator, <lambda at
../../Dropbox/Client2012/Tools/moo.cpp:7:29> >, <lambda at
../../Dropbox/Client2012/Tools/moo.cpp:7:29> >' requested here
return startThreadEngine(new SequenceHolderType(sequence, functor));
^
/Qt/5.0/qtbase/include/QtConcurrent/../../src/concurrent/qtconcurrentmap.h:182:12:
note: in instantiation of function template specialization
'QtConcurrent::startMapped<void, QList<int>, <lambda at
../../Dropbox/Client2012/Tools/moo.cpp:7:29> >' requested here
return startMapped<typename QtPrivate::MapResultType<void,
MapFunctor>::ResultType>(sequence, QtPrivate::createFunctionWrapper(map));
^
../../Dropbox/Client2012/Tools/moo.cpp:7:2: note: in instantiation of
function template specialization 'QtConcurrent::mapped<QList<int>,
<lambda at ../../Dropbox/Client2012/Tools/moo.cpp:7:29> >' requested here
QtConcurrent::mapped(list, [](int i){ return foo(i); });
^
In file included from ../../Dropbox/Client2012/Tools/moo.cpp:1:
In file included from /Qt/5.0/qtbase/include/QtConcurrent/QtConcurrent:11:
In file included from
/Qt/5.0/qtbase/include/QtConcurrent/qtconcurrentfilter.h:1:
In file included from
/Qt/5.0/qtbase/include/QtConcurrent/../../src/concurrent/qtconcurrentfilter.h:49:
In file included from
/Qt/5.0/qtbase/include/QtConcurrent/qtconcurrentfilterkernel.h:1:
In file included from
/Qt/5.0/qtbase/include/QtConcurrent/../../src/concurrent/qtconcurrentfilterkernel.h:50:
In file included from
/Qt/5.0/qtbase/include/QtConcurrent/qtconcurrentmapkernel.h:1:
/Qt/5.0/qtbase/include/QtConcurrent/../../src/concurrent/qtconcurrentmapkernel.h:169:34:
error: no type named 'result_type' in '<lambda at
../../Dropbox/Client2012/Tools/moo.cpp:7:29>'
typedef typename MapFunctor::result_type T;
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
2 errors generated.
More information about the Development
mailing list