42 #ifndef QTCONCURRENT_FUNCTIONWRAPPERS_H 43 #define QTCONCURRENT_FUNCTIONWRAPPERS_H 45 #include <QtCore/qglobal.h> 47 #ifndef QT_NO_CONCURRENT 59 class FunctionWrapper0
62 typedef T (*FunctionPointerType)();
63 typedef T result_type;
64 inline FunctionWrapper0(FunctionPointerType _functionPointer)
65 :functionPointer(_functionPointer) { }
69 return functionPointer();
72 FunctionPointerType functionPointer;
75 template <
typename T,
typename U>
76 class FunctionWrapper1
79 typedef T (*FunctionPointerType)(U
u);
80 typedef T result_type;
81 inline FunctionWrapper1(FunctionPointerType _functionPointer)
82 :functionPointer(_functionPointer) { }
84 inline T operator()(U
u)
86 return functionPointer(u);
90 FunctionPointerType functionPointer;
93 template <
typename T,
typename U,
typename V>
94 class FunctionWrapper2
97 typedef T (*FunctionPointerType)(U
u, V v);
98 typedef T result_type;
99 inline FunctionWrapper2(FunctionPointerType _functionPointer)
100 :functionPointer(_functionPointer) { }
102 inline T operator()(U u, V v)
104 return functionPointer(u, v);
107 FunctionPointerType functionPointer;
110 template <
typename T,
typename C>
111 class MemberFunctionWrapper
114 typedef T (C::*FunctionPointerType)();
115 typedef T result_type;
116 inline MemberFunctionWrapper(FunctionPointerType _functionPointer)
117 :functionPointer(_functionPointer) { }
119 inline T operator()(C &
c)
121 return (c.*functionPointer)();
124 FunctionPointerType functionPointer;
127 template <
typename T,
typename C,
typename U>
128 class MemberFunctionWrapper1
131 typedef T (C::*FunctionPointerType)(U);
132 typedef T result_type;
134 inline MemberFunctionWrapper1(FunctionPointerType _functionPointer)
135 : functionPointer(_functionPointer)
138 inline T operator()(C &
c, U
u)
140 return (c.*functionPointer)(
u);
144 FunctionPointerType functionPointer;
147 template <
typename T,
typename C>
148 class ConstMemberFunctionWrapper
151 typedef T (C::*FunctionPointerType)()
const;
152 typedef T result_type;
153 inline ConstMemberFunctionWrapper(FunctionPointerType _functionPointer)
154 :functionPointer(_functionPointer) { }
156 inline T operator()(
const C &
c)
const 158 return (c.*functionPointer)();
161 FunctionPointerType functionPointer;
168 template <
typename T>
169 const T& createFunctionWrapper(
const T& t)
174 template <
typename T,
typename U>
175 QtConcurrent::FunctionWrapper1<T, U> createFunctionWrapper(T (*func)(U))
177 return QtConcurrent::FunctionWrapper1<T, U>(func);
180 template <
typename T,
typename C>
181 QtConcurrent::MemberFunctionWrapper<T, C> createFunctionWrapper(T (C::*func)())
183 return QtConcurrent::MemberFunctionWrapper<T, C>(func);
186 template <
typename T,
typename C,
typename U>
187 QtConcurrent::MemberFunctionWrapper1<T, C, U> createFunctionWrapper(T (C::*func)(U))
189 return QtConcurrent::MemberFunctionWrapper1<T, C, U>(func);
192 template <
typename T,
typename C>
193 QtConcurrent::ConstMemberFunctionWrapper<T, C> createFunctionWrapper(T (C::*func)()
const)
195 return QtConcurrent::ConstMemberFunctionWrapper<T, C>(func);
198 struct PushBackWrapper
200 typedef void result_type;
202 template <
class C,
class U>
203 inline void operator()(C &
c,
const U &
u)
const 205 return c.push_back(u);
208 #ifdef Q_COMPILER_RVALUE_REFS 209 template <
class C,
class U>
210 inline void operator()(C &c, U &&u)
const 212 return c.push_back(u);
217 template <typename Functor, bool foo = HasResultType<Functor>::Value>
218 struct LazyResultType {
typedef typename Functor::result_type
Type; };
219 template <
typename Functor>
220 struct LazyResultType<Functor, false> {
typedef void Type; };
223 struct ReduceResultType;
225 template <
class U,
class V>
226 struct ReduceResultType<void(*)(U&,V)>
228 typedef U ResultType;
231 template <
class T,
class C,
class U>
232 struct ReduceResultType<T(C::*)(U)>
234 typedef C ResultType;
237 template <
class InputSequence,
class MapFunctor>
243 template <
class U,
class V>
244 struct MapResultType<void, U (*)(V)>
246 typedef U ResultType;
249 template <
class T,
class C>
250 struct MapResultType<void, T(C::*)() const>
252 typedef T ResultType;
255 #ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS 257 template <
template <
typename>
class InputSequence,
typename MapFunctor,
typename T>
258 struct MapResultType<InputSequence<T>, MapFunctor>
263 template <
template <
typename>
class InputSequence,
class T,
class U,
class V>
264 struct MapResultType<InputSequence<T>, U (*)(V)>
266 typedef InputSequence<U> ResultType;
269 template <
template <
typename>
class InputSequence,
class T,
class U,
class C>
270 struct MapResultType<InputSequence<T>, U(C::*)() const>
272 typedef InputSequence<U> ResultType;
275 #endif // QT_NO_TEMPLATE_TEMPLATE_PARAMETER 277 template <
class MapFunctor>
283 template <
class U,
class V>
289 template <
class U,
class C>
302 #endif // QT_NO_CONCURRENT
#define QT_END_NAMESPACE
This macro expands to.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QStringList class provides a list of strings.
The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded pro...
The QList class is a template class that provides lists.