summaryrefslogtreecommitdiffstats
path: root/src/corelib/concurrent/qtconcurrentstoredfunctioncall.h
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2011-04-18 12:07:32 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2011-05-19 13:09:31 (GMT)
commit917f2ff617209bcc283eb3590b422bcf239c0537 (patch)
tree8a58ff1f428c85546303864eea7229c8e341cbe9 /src/corelib/concurrent/qtconcurrentstoredfunctioncall.h
parent837f18f043b18410c1d93b9f1156acf729dad510 (diff)
downloadQt-917f2ff617209bcc283eb3590b422bcf239c0537.zip
Qt-917f2ff617209bcc283eb3590b422bcf239c0537.tar.gz
Qt-917f2ff617209bcc283eb3590b422bcf239c0537.tar.bz2
Support of lambdas in QtConcurrent::run
Reviewed-by: Joao
Diffstat (limited to 'src/corelib/concurrent/qtconcurrentstoredfunctioncall.h')
-rw-r--r--src/corelib/concurrent/qtconcurrentstoredfunctioncall.h105
1 files changed, 45 insertions, 60 deletions
diff --git a/src/corelib/concurrent/qtconcurrentstoredfunctioncall.h b/src/corelib/concurrent/qtconcurrentstoredfunctioncall.h
index 82d95f6..2a90e39 100644
--- a/src/corelib/concurrent/qtconcurrentstoredfunctioncall.h
+++ b/src/corelib/concurrent/qtconcurrentstoredfunctioncall.h
@@ -66,10 +66,10 @@ struct StoredFunctorCall0: public RunFunctionTask<T>
};
-template <typename T, typename FunctionPointer>
-struct VoidStoredFunctorCall0: public RunFunctionTask<T>
+template <typename FunctionPointer>
+struct StoredFunctorCall0<void, FunctionPointer>: public RunFunctionTask<void>
{
- inline VoidStoredFunctorCall0(FunctionPointer _function)
+ inline StoredFunctorCall0(FunctionPointer _function)
: function(_function) {}
void runFunctor() { function(); }
FunctionPointer function;
@@ -77,13 +77,6 @@ struct VoidStoredFunctorCall0: public RunFunctionTask<T>
};
template <typename T, typename FunctionPointer>
-struct SelectStoredFunctorCall0
-{
- typedef typename SelectSpecialization<T>::template
- Type<StoredFunctorCall0 <T, FunctionPointer>,
- VoidStoredFunctorCall0<T, FunctionPointer> >::type type;
-};
-template <typename T, typename FunctionPointer>
struct StoredFunctorPointerCall0: public RunFunctionTask<T>
{
inline StoredFunctorPointerCall0(FunctionPointer * _function)
@@ -276,10 +269,10 @@ struct StoredFunctorCall1: public RunFunctionTask<T>
Arg1 arg1;
};
-template <typename T, typename FunctionPointer, typename Arg1>
-struct VoidStoredFunctorCall1: public RunFunctionTask<T>
+template <typename FunctionPointer, typename Arg1>
+struct StoredFunctorCall1<void, FunctionPointer, Arg1>: public RunFunctionTask<void>
{
- inline VoidStoredFunctorCall1(FunctionPointer _function, const Arg1 &_arg1)
+ inline StoredFunctorCall1(FunctionPointer _function, const Arg1 &_arg1)
: function(_function), arg1(_arg1) {}
void runFunctor() { function(arg1); }
FunctionPointer function;
@@ -287,13 +280,6 @@ struct VoidStoredFunctorCall1: public RunFunctionTask<T>
};
template <typename T, typename FunctionPointer, typename Arg1>
-struct SelectStoredFunctorCall1
-{
- typedef typename SelectSpecialization<T>::template
- Type<StoredFunctorCall1 <T, FunctionPointer, Arg1>,
- VoidStoredFunctorCall1<T, FunctionPointer, Arg1> >::type type;
-};
-template <typename T, typename FunctionPointer, typename Arg1>
struct StoredFunctorPointerCall1: public RunFunctionTask<T>
{
inline StoredFunctorPointerCall1(FunctionPointer * _function, const Arg1 &_arg1)
@@ -486,10 +472,10 @@ struct StoredFunctorCall2: public RunFunctionTask<T>
Arg1 arg1; Arg2 arg2;
};
-template <typename T, typename FunctionPointer, typename Arg1, typename Arg2>
-struct VoidStoredFunctorCall2: public RunFunctionTask<T>
+template <typename FunctionPointer, typename Arg1, typename Arg2>
+struct StoredFunctorCall2<void, FunctionPointer, Arg1, Arg2>: public RunFunctionTask<void>
{
- inline VoidStoredFunctorCall2(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2)
+ inline StoredFunctorCall2(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2)
: function(_function), arg1(_arg1), arg2(_arg2) {}
void runFunctor() { function(arg1, arg2); }
FunctionPointer function;
@@ -497,13 +483,6 @@ struct VoidStoredFunctorCall2: public RunFunctionTask<T>
};
template <typename T, typename FunctionPointer, typename Arg1, typename Arg2>
-struct SelectStoredFunctorCall2
-{
- typedef typename SelectSpecialization<T>::template
- Type<StoredFunctorCall2 <T, FunctionPointer, Arg1, Arg2>,
- VoidStoredFunctorCall2<T, FunctionPointer, Arg1, Arg2> >::type type;
-};
-template <typename T, typename FunctionPointer, typename Arg1, typename Arg2>
struct StoredFunctorPointerCall2: public RunFunctionTask<T>
{
inline StoredFunctorPointerCall2(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2)
@@ -696,10 +675,10 @@ struct StoredFunctorCall3: public RunFunctionTask<T>
Arg1 arg1; Arg2 arg2; Arg3 arg3;
};
-template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3>
-struct VoidStoredFunctorCall3: public RunFunctionTask<T>
+template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3>
+struct StoredFunctorCall3<void, FunctionPointer, Arg1, Arg2, Arg3>: public RunFunctionTask<void>
{
- inline VoidStoredFunctorCall3(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3)
+ inline StoredFunctorCall3(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3)
: function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3) {}
void runFunctor() { function(arg1, arg2, arg3); }
FunctionPointer function;
@@ -707,13 +686,6 @@ struct VoidStoredFunctorCall3: public RunFunctionTask<T>
};
template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3>
-struct SelectStoredFunctorCall3
-{
- typedef typename SelectSpecialization<T>::template
- Type<StoredFunctorCall3 <T, FunctionPointer, Arg1, Arg2, Arg3>,
- VoidStoredFunctorCall3<T, FunctionPointer, Arg1, Arg2, Arg3> >::type type;
-};
-template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3>
struct StoredFunctorPointerCall3: public RunFunctionTask<T>
{
inline StoredFunctorPointerCall3(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3)
@@ -906,10 +878,10 @@ struct StoredFunctorCall4: public RunFunctionTask<T>
Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4;
};
-template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
-struct VoidStoredFunctorCall4: public RunFunctionTask<T>
+template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
+struct StoredFunctorCall4<void, FunctionPointer, Arg1, Arg2, Arg3, Arg4>: public RunFunctionTask<void>
{
- inline VoidStoredFunctorCall4(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4)
+ inline StoredFunctorCall4(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4)
: function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4) {}
void runFunctor() { function(arg1, arg2, arg3, arg4); }
FunctionPointer function;
@@ -917,13 +889,6 @@ struct VoidStoredFunctorCall4: public RunFunctionTask<T>
};
template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
-struct SelectStoredFunctorCall4
-{
- typedef typename SelectSpecialization<T>::template
- Type<StoredFunctorCall4 <T, FunctionPointer, Arg1, Arg2, Arg3, Arg4>,
- VoidStoredFunctorCall4<T, FunctionPointer, Arg1, Arg2, Arg3, Arg4> >::type type;
-};
-template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
struct StoredFunctorPointerCall4: public RunFunctionTask<T>
{
inline StoredFunctorPointerCall4(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4)
@@ -1116,10 +1081,10 @@ struct StoredFunctorCall5: public RunFunctionTask<T>
Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5;
};
-template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
-struct VoidStoredFunctorCall5: public RunFunctionTask<T>
+template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
+struct StoredFunctorCall5<void, FunctionPointer, Arg1, Arg2, Arg3, Arg4, Arg5>: public RunFunctionTask<void>
{
- inline VoidStoredFunctorCall5(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5)
+ inline StoredFunctorCall5(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5)
: function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5) {}
void runFunctor() { function(arg1, arg2, arg3, arg4, arg5); }
FunctionPointer function;
@@ -1127,13 +1092,6 @@ struct VoidStoredFunctorCall5: public RunFunctionTask<T>
};
template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
-struct SelectStoredFunctorCall5
-{
- typedef typename SelectSpecialization<T>::template
- Type<StoredFunctorCall5 <T, FunctionPointer, Arg1, Arg2, Arg3, Arg4, Arg5>,
- VoidStoredFunctorCall5<T, FunctionPointer, Arg1, Arg2, Arg3, Arg4, Arg5> >::type type;
-};
-template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
struct StoredFunctorPointerCall5: public RunFunctionTask<T>
{
inline StoredFunctorPointerCall5(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5)
@@ -1316,6 +1274,33 @@ struct SelectStoredConstMemberFunctionPointerCall5
Type<StoredConstMemberFunctionPointerCall5 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>,
VoidStoredConstMemberFunctionPointerCall5<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5> >::type type;
};
+
+template <typename T, typename Functor>
+class StoredFunctorCall : public RunFunctionTask<T>
+{
+public:
+ StoredFunctorCall(const Functor &f) : functor(f) { }
+ void runFunctor()
+ {
+ this->result = functor();
+ }
+private:
+ Functor functor;
+};
+template <typename Functor>
+class StoredFunctorCall<void, Functor> : public RunFunctionTask<void>
+{
+public:
+ StoredFunctorCall(const Functor &f) : functor(f) { }
+ void runFunctor()
+ {
+ functor();
+ }
+private:
+ Functor functor;
+};
+
+
} //namespace QtConcurrent
#endif // qdoc