From d3e5fc0220e57d5a9bba35780915c53790ff249f Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 18 Apr 2011 14:07:32 +0200 Subject: Support of lambdas in QtConcurrent::run Reviewed-by: Joao (cherry picked from commit 917f2ff617209bcc283eb3590b422bcf239c0537) Change-Id: I837f18f043b18410c1d93b9f1156acf729dad510 Reviewed-on: http://codereview.qt.nokia.com/142 Reviewed-by: Olivier Goffart --- src/corelib/concurrent/qtconcurrentrun.h | 75 +++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 12 deletions(-) (limited to 'src/corelib/concurrent/qtconcurrentrun.h') diff --git a/src/corelib/concurrent/qtconcurrentrun.h b/src/corelib/concurrent/qtconcurrentrun.h index 8611fba361..ef51b2adcb 100644 --- a/src/corelib/concurrent/qtconcurrentrun.h +++ b/src/corelib/concurrent/qtconcurrentrun.h @@ -71,63 +71,114 @@ namespace QtConcurrent { template QFuture run(T (*functionPointer)()) { - return (new QT_TYPENAME SelectStoredFunctorCall0::type(functionPointer))->start(); + return (new StoredFunctorCall0(functionPointer))->start(); } template QFuture run(T (*functionPointer)(Param1), const Arg1 &arg1) { - return (new QT_TYPENAME SelectStoredFunctorCall1::type(functionPointer, arg1))->start(); + return (new StoredFunctorCall1(functionPointer, arg1))->start(); } template QFuture run(T (*functionPointer)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2) { - return (new QT_TYPENAME SelectStoredFunctorCall2::type(functionPointer, arg1, arg2))->start(); + return (new StoredFunctorCall2(functionPointer, arg1, arg2))->start(); } template QFuture run(T (*functionPointer)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) { - return (new QT_TYPENAME SelectStoredFunctorCall3::type(functionPointer, arg1, arg2, arg3))->start(); + return (new StoredFunctorCall3(functionPointer, arg1, arg2, arg3))->start(); } template QFuture run(T (*functionPointer)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) { - return (new QT_TYPENAME SelectStoredFunctorCall4::type(functionPointer, arg1, arg2, arg3, arg4))->start(); + return (new StoredFunctorCall4(functionPointer, arg1, arg2, arg3, arg4))->start(); } template QFuture run(T (*functionPointer)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) { - return (new QT_TYPENAME SelectStoredFunctorCall5::type(functionPointer, arg1, arg2, arg3, arg4, arg5))->start(); + return (new StoredFunctorCall5(functionPointer, arg1, arg2, arg3, arg4, arg5))->start(); } +#ifdef Q_COMPILER_DECLTYPE + +template +auto run(Functor functor) -> typename QtPrivate::QEnableIf::Value, QFuture >::Type +{ + typedef decltype(functor()) result_type; + return (new StoredFunctorCall0(functor))->start(); +} + +template +auto run(Functor functor, const Arg1 &arg1) + -> typename QtPrivate::QEnableIf::Value, QFuture >::Type +{ + typedef decltype(functor(arg1)) result_type; + return (new StoredFunctorCall1(functor, arg1))->start(); +} + +template +auto run(Functor functor, const Arg1 &arg1, const Arg2 &arg2) + -> typename QtPrivate::QEnableIf::Value, QFuture >::Type +{ + typedef decltype(functor(arg1, arg2)) result_type; + return (new StoredFunctorCall2(functor, arg1, arg2))->start(); +} + +template +auto run(Functor functor, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) + -> typename QtPrivate::QEnableIf::Value, QFuture >::Type +{ + typedef decltype(functor(arg1, arg2, arg3)) result_type; + return (new StoredFunctorCall3(functor, arg1, arg2, arg3))->start(); +} + +template +auto run(Functor functor, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) + -> typename QtPrivate::QEnableIf::Value, QFuture >::Type +{ + typedef decltype(functor(arg1, arg2, arg3, arg4)) result_type; + return (new StoredFunctorCall4(functor, arg1, arg2, arg3, arg4))->start(); +} + +template +auto run(Functor functor, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) + -> typename QtPrivate::QEnableIf::Value, QFuture >::Type +{ + typedef decltype(functor(arg1, arg2, arg3, arg4, arg5)) result_type; + return (new StoredFunctorCall5(functor, arg1, arg2, arg3, arg4, arg5))->start(); +} + +#endif + template QFuture run(FunctionObject functionObject) { - return (new QT_TYPENAME SelectStoredFunctorCall0::type(functionObject))->start(); + return (new StoredFunctorCall0(functionObject))->start(); } template QFuture run(FunctionObject functionObject, const Arg1 &arg1) { - return (new QT_TYPENAME SelectStoredFunctorCall1::type(functionObject, arg1))->start(); + return (new StoredFunctorCall1(functionObject, arg1))->start(); } template QFuture run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2) { - return (new QT_TYPENAME SelectStoredFunctorCall2::type(functionObject, arg1, arg2))->start(); + return (new StoredFunctorCall2(functionObject, arg1, arg2))->start(); } template QFuture run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) { - return (new QT_TYPENAME SelectStoredFunctorCall3::type(functionObject, arg1, arg2, arg3))->start(); + return (new StoredFunctorCall3(functionObject, arg1, arg2, arg3))->start(); } template QFuture run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) { - return (new QT_TYPENAME SelectStoredFunctorCall4::type(functionObject, arg1, arg2, arg3, arg4))->start(); + return (new StoredFunctorCall4(functionObject, arg1, arg2, arg3, arg4))->start(); } template QFuture run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) { - return (new QT_TYPENAME SelectStoredFunctorCall5::type(functionObject, arg1, arg2, arg3, arg4, arg5))->start(); + return (new StoredFunctorCall5(functionObject, arg1, arg2, arg3, arg4, arg5))->start(); } template -- cgit v1.2.3