diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2011-05-19 12:15:26 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2011-05-19 12:15:26 (GMT) |
commit | 37c4cd4801106112b638ed9d2164b87bbc0a0d1e (patch) | |
tree | 3dcc9e1b9908328d1355f5746fd77de7030b547f /src/corelib/concurrent/qtconcurrentmap.h | |
parent | b6a6953d21a95c402e8a5010c1ea5131509eeea3 (diff) | |
parent | 35b5f15c3fe5c2f1f0d046d09b9d95dee3bb91b5 (diff) | |
download | Qt-37c4cd4801106112b638ed9d2164b87bbc0a0d1e.zip Qt-37c4cd4801106112b638ed9d2164b87bbc0a0d1e.tar.gz Qt-37c4cd4801106112b638ed9d2164b87bbc0a0d1e.tar.bz2 |
Merge branch '4.8-upstream'
Diffstat (limited to 'src/corelib/concurrent/qtconcurrentmap.h')
-rw-r--r-- | src/corelib/concurrent/qtconcurrentmap.h | 632 |
1 files changed, 86 insertions, 546 deletions
diff --git a/src/corelib/concurrent/qtconcurrentmap.h b/src/corelib/concurrent/qtconcurrentmap.h index 80edf7e..a857ab5 100644 --- a/src/corelib/concurrent/qtconcurrentmap.h +++ b/src/corelib/concurrent/qtconcurrentmap.h @@ -110,38 +110,14 @@ namespace QtConcurrent { template <typename Sequence, typename MapFunctor> QFuture<void> map(Sequence &sequence, MapFunctor map) { - return startMap(sequence.begin(), sequence.end(), map); -} - -template <typename Sequence, typename T, typename U> -QFuture<void> map(Sequence &sequence, T (map)(U)) -{ - return startMap(sequence.begin(), sequence.end(), FunctionWrapper1<T, U>(map)); -} - -template <typename Sequence, typename T, typename C> -QFuture<void> map(Sequence &sequence, T (C::*map)()) -{ - return startMap(sequence.begin(), sequence.end(), MemberFunctionWrapper<T, C>(map)); + return startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map)); } // map() on iterators template <typename Iterator, typename MapFunctor> QFuture<void> map(Iterator begin, Iterator end, MapFunctor map) { - return startMap(begin, end, map); -} - -template <typename Iterator, typename T, typename U> -QFuture<void> map(Iterator begin, Iterator end, T (map)(U)) -{ - return startMap(begin, end, FunctionWrapper1<T, U>(map)); -} - -template <typename Iterator, typename T, typename C> -QFuture<void> map(Iterator begin, Iterator end, T (C::*map)()) -{ - return startMap(begin, end, MemberFunctionWrapper<T, C>(map)); + return startMap(begin, end, QtPrivate::createFunctionWrapper(map)); } // mappedReduced() for sequences. @@ -151,88 +127,24 @@ QFuture<ResultType> mappedReduced(const Sequence &sequence, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced<typename MapFunctor::result_type, ResultType> - (sequence, map, reduce, options); -} - -template <typename Sequence, typename MapFunctor, typename T, typename U, typename V> -QFuture<U> mappedReduced(const Sequence &sequence, - MapFunctor map, - T (reduce)(U &, V), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<typename MapFunctor::result_type, U> - (sequence, map, FunctionWrapper2<T, U &, V>(reduce), options); -} - -template <typename Sequence, typename MapFunctor, typename T, typename C, typename U> -QFuture<C> mappedReduced(const Sequence &sequence, - MapFunctor map, - T (C::*reduce)(U), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<typename MapFunctor::result_type, C> - (sequence, map, MemberFunctionWrapper1<T, C, U>(reduce), options); -} - -template <typename ResultType, typename Sequence, typename T, typename U, typename ReduceFunctor> -QFuture<ResultType> mappedReduced(const Sequence &sequence, - T (map)(U), - ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<T, ResultType> - (sequence, FunctionWrapper1<T, U>(map), reduce, options); + return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> + (sequence, + QtPrivate::createFunctionWrapper(map), + QtPrivate::createFunctionWrapper(reduce), + options); } -template <typename ResultType, typename Sequence, typename T, typename C, typename ReduceFunctor> -QFuture<ResultType> mappedReduced(const Sequence &sequence, - T (C::*map)() const, +template <typename Sequence, typename MapFunctor, typename ReduceFunctor> +QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(const Sequence &sequence, + MapFunctor map, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced<T, ResultType> - (sequence, ConstMemberFunctionWrapper<T, C>(map), reduce, options); -} - -template <typename Sequence, typename T, typename U, typename V, typename W, typename X> -QFuture<W> mappedReduced(const Sequence &sequence, - T (map)(U), - V (reduce)(W &, X), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<T, W> - (sequence, FunctionWrapper1<T, U>(map), FunctionWrapper2<V, W &, X>(reduce), options); -} - -template <typename Sequence, typename T, typename C, typename U, typename V, typename W> -QFuture<V> mappedReduced(const Sequence &sequence, - T (C::*map)() const, - U (reduce)(V &, W), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<T, V> (sequence, ConstMemberFunctionWrapper<T, C>(map), - FunctionWrapper2<U, V &, W>(reduce), options); -} - -template <typename Sequence, typename T, typename U, typename V, typename C, typename W> -QFuture<C> mappedReduced(const Sequence &sequence, - T (map)(U), - V (C::*reduce)(W), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<T, C> (sequence, FunctionWrapper1<T, U>(map), - MemberFunctionWrapper1<V, C, W>(reduce), options); -} - -template <typename Sequence, typename T, typename C, typename U,typename D, typename V> -QFuture<D> mappedReduced(const Sequence &sequence, - T (C::*map)() const, - U (D::*reduce)(V), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<T, D>(sequence, ConstMemberFunctionWrapper<T, C>(map), - MemberFunctionWrapper1<U, D, V>(reduce), options); + return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> + (sequence, + QtPrivate::createFunctionWrapper(map), + QtPrivate::createFunctionWrapper(reduce), + options); } // mappedReduced() for iterators @@ -243,295 +155,85 @@ QFuture<ResultType> mappedReduced(Iterator begin, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced<ResultType, typename MapFunctor::result_type> - (begin, end, map, reduce, options); -} - -template <typename Iterator, typename MapFunctor, typename T, typename U, typename V> -QFuture<U> mappedReduced(Iterator begin, - Iterator end, - MapFunctor map, - T (reduce)(U &, V), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<typename MapFunctor::result_type, U> - (begin, end, map, FunctionWrapper2<T, U &, V>(reduce), options); -} - -template <typename Iterator, typename MapFunctor, typename T, typename C, typename U> -QFuture<C> mappedReduced(Iterator begin, - Iterator end, - MapFunctor map, - T (C::*reduce)(U), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<typename MapFunctor::result_type, C> - (begin, end, map, MemberFunctionWrapper1<T, C, U>(reduce), options); + return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> + (begin, end, + QtPrivate::createFunctionWrapper(map), + QtPrivate::createFunctionWrapper(reduce), + options); } -template <typename ResultType, typename Iterator, typename T, typename U, typename ReduceFunctor> -QFuture<ResultType> mappedReduced(Iterator begin, +template <typename Iterator, typename MapFunctor, typename ReduceFunctor> +QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(Iterator begin, Iterator end, - T (map)(U), - ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<T, ResultType> - (begin, end, FunctionWrapper1<T, U>(map), reduce, options); -} - -template <typename ResultType, typename Iterator, typename T, typename C, typename ReduceFunctor> -QFuture<ResultType> mappedReduced(Iterator begin, - Iterator end, - T (C::*map)() const, + MapFunctor map, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced<T, ResultType> - (begin, end, ConstMemberFunctionWrapper<T, C>(map), reduce, options); -} - -template <typename Iterator, typename T, typename U, typename V, typename W, typename X> -QFuture<W> mappedReduced(Iterator begin, - Iterator end, - T (map)(U), - V (reduce)(W &, X), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<T, W> - (begin, end, FunctionWrapper1<T, U>(map), FunctionWrapper2<V, W &, X>(reduce), options); -} - -template <typename Iterator, typename T, typename C, typename U, typename V, typename W> -QFuture<V> mappedReduced(Iterator begin, - Iterator end, - T (C::*map)() const, - U (reduce)(V &, W), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<T, V>(begin, end, ConstMemberFunctionWrapper<T, C>(map), - FunctionWrapper2<U, V &, W>(reduce), options); -} - -template <typename Iterator, typename T, typename U, typename V, typename C, typename W> -QFuture<C> mappedReduced(Iterator begin, - Iterator end, - T (map)(U), - V (C::*reduce)(W), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<T, C> - (begin, end, FunctionWrapper1<T, U>(map), MemberFunctionWrapper1<V, C, W>(reduce), options); -} - -template <typename Iterator, typename T, typename C, typename U,typename D, typename V> -QFuture<D> mappedReduced(Iterator begin, - Iterator end, - T (C::*map)() const, - U (D::*reduce)(V), - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<T, D>(begin, end, ConstMemberFunctionWrapper<T, C>(map), - MemberFunctionWrapper1<U, D, V>(reduce), options); + return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> + (begin, end, + QtPrivate::createFunctionWrapper(map), + QtPrivate::createFunctionWrapper(reduce), + options); } // mapped() for sequences template <typename Sequence, typename MapFunctor> -QFuture<typename MapFunctor::result_type> mapped(const Sequence &sequence, MapFunctor map) +QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> mapped(const Sequence &sequence, MapFunctor map) { - return startMapped<typename MapFunctor::result_type>(sequence, map); -} - -template <typename Sequence, typename T, typename U> -QFuture<T> mapped(const Sequence &sequence, T (map)(U)) -{ - return startMapped<T>(sequence, FunctionWrapper1<T, U>(map)); -} - -template <typename Sequence, typename T, typename C> -QFuture<T> mapped(const Sequence &sequence, T (C::*map)() const) -{ - return startMapped<T>(sequence, ConstMemberFunctionWrapper<T, C>(map)); + return startMapped<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType>(sequence, QtPrivate::createFunctionWrapper(map)); } // mapped() for iterator ranges. template <typename Iterator, typename MapFunctor> -QFuture<typename MapFunctor::result_type> mapped(Iterator begin, Iterator end, MapFunctor map) -{ - return startMapped<Q_TYPENAME MapFunctor::result_type>(begin, end, map); -} - -template <typename Iterator, typename T, typename U> -QFuture<T> mapped(Iterator begin, Iterator end, T (map)(U)) +QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> mapped(Iterator begin, Iterator end, MapFunctor map) { - return startMapped<T>(begin, end, FunctionWrapper1<T, U>(map)); + return startMapped<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType>(begin, end, QtPrivate::createFunctionWrapper(map)); } -template <typename Iterator, typename T, typename C> -QFuture<T> mapped(Iterator begin, Iterator end, T (C::*map)() const) -{ - return startMapped<T>(begin, end, ConstMemberFunctionWrapper<T, C>(map)); -} - - +// blockingMap() for sequences template <typename Sequence, typename MapFunctor> void blockingMap(Sequence &sequence, MapFunctor map) { - startMap(sequence.begin(), sequence.end(), map).startBlocking(); -} - -template <typename Sequence, typename T, typename U> -void blockingMap(Sequence &sequence, T (map)(U)) -{ - startMap(sequence.begin(), sequence.end(), QtConcurrent::FunctionWrapper1<T, U>(map)).startBlocking(); -} - -template <typename Sequence, typename T, typename C> -void blockingMap(Sequence &sequence, T (C::*map)()) -{ - startMap(sequence.begin(), sequence.end(), QtConcurrent::MemberFunctionWrapper<T, C>(map)).startBlocking(); + startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map)).startBlocking(); } +// blockingMap() for iterator ranges template <typename Iterator, typename MapFunctor> void blockingMap(Iterator begin, Iterator end, MapFunctor map) { - startMap(begin, end, map).startBlocking(); -} - -template <typename Iterator, typename T, typename U> -void blockingMap(Iterator begin, Iterator end, T (map)(U)) -{ - startMap(begin, end, QtConcurrent::FunctionWrapper1<T, U>(map)).startBlocking(); -} - -template <typename Iterator, typename T, typename C> -void blockingMap(Iterator begin, Iterator end, T (C::*map)()) -{ - startMap(begin, end, QtConcurrent::MemberFunctionWrapper<T, C>(map)).startBlocking(); + startMap(begin, end, QtPrivate::createFunctionWrapper(map)).startBlocking(); } +// blockingMappedReduced() for sequences template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType blockingMappedReduced(const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, ResultType> - (sequence, map, reduce, options).startBlocking(); -} - -template <typename Sequence, typename MapFunctor, typename T, typename U, typename V> -U blockingMappedReduced(const Sequence &sequence, - MapFunctor map, - T (reduce)(U &, V), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, U> - (sequence, - map, - QtConcurrent::FunctionWrapper2<T, U &, V>(reduce), - options) - .startBlocking(); -} - -template <typename Sequence, typename MapFunctor, typename T, typename C, typename U> -C blockingMappedReduced(const Sequence &sequence, - MapFunctor map, - T (C::*reduce)(U), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, C> - (sequence, - map, - QtConcurrent::MemberFunctionWrapper1<T, C, U>(reduce), - options) - .startBlocking(); -} - -template <typename ResultType, typename Sequence, typename T, typename U, typename ReduceFunctor> -ResultType blockingMappedReduced(const Sequence &sequence, - T (map)(U), - ReduceFunctor reduce, - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<T, ResultType> + return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> (sequence, - QtConcurrent::FunctionWrapper1<T, U>(map), - reduce, + QtPrivate::createFunctionWrapper(map), + QtPrivate::createFunctionWrapper(reduce), options) .startBlocking(); } -template <typename ResultType, typename Sequence, typename T, typename C, typename ReduceFunctor> -ResultType blockingMappedReduced(const Sequence &sequence, - T (C::*map)() const, +template <typename MapFunctor, typename ReduceFunctor, typename Sequence> +typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(const Sequence &sequence, + MapFunctor map, ReduceFunctor reduce, - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<T, ResultType> - (sequence, - QtConcurrent::ConstMemberFunctionWrapper<T, C>(map), - reduce, - options) - .startBlocking(); -} - -template <typename Sequence, typename T, typename U, typename V, typename W, typename X> -W blockingMappedReduced(const Sequence &sequence, - T (map)(U), - V (reduce)(W &, X), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<T, W> - (sequence, - QtConcurrent::FunctionWrapper1<T, U>(map), - QtConcurrent::FunctionWrapper2<V, W &, X>(reduce), - options) - .startBlocking(); -} - -template <typename Sequence, typename T, typename C, typename U, typename V, typename W> -V blockingMappedReduced(const Sequence &sequence, - T (C::*map)() const, - U (reduce)(V &, W), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<T, V> - (sequence, - QtConcurrent::ConstMemberFunctionWrapper<T, C>(map), - QtConcurrent::FunctionWrapper2<U, V &, W>(reduce), - options) - .startBlocking(); -} - -template <typename Sequence, typename T, typename U, typename V, typename C, typename W> -C blockingMappedReduced(const Sequence &sequence, - T (map)(U), - V (C::*reduce)(W), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<T, C> - (sequence, - QtConcurrent::FunctionWrapper1<T, U>(map), - QtConcurrent::MemberFunctionWrapper1<V, C, W>(reduce), - options) - .startBlocking(); -} - -template <typename Sequence, typename T, typename C, typename U,typename D, typename V> -D blockingMappedReduced(const Sequence &sequence, - T (C::*map)() const, - U (D::*reduce)(V), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) + ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced<T, D> + return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> (sequence, - QtConcurrent::ConstMemberFunctionWrapper<T, C>(map), - QtConcurrent::MemberFunctionWrapper1<U, D, V>(reduce), + QtPrivate::createFunctionWrapper(map), + QtPrivate::createFunctionWrapper(reduce), options) .startBlocking(); } +// blockingMappedReduced() for iterator ranges template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> ResultType blockingMappedReduced(Iterator begin, Iterator end, @@ -539,134 +241,25 @@ ResultType blockingMappedReduced(Iterator begin, ReduceFunctor reduce, QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) { - return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, ResultType> - (begin, end, map, reduce, options).startBlocking(); -} - -template <typename Iterator, typename MapFunctor, typename T, typename U, typename V> -U blockingMappedReduced(Iterator begin, - Iterator end, - MapFunctor map, - T (reduce)(U &, V), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, U> - (begin, - end, - map, - QtConcurrent::FunctionWrapper2<T, U &, V>(reduce), - options) - .startBlocking(); -} - -template <typename Iterator, typename MapFunctor, typename T, typename C, typename U> -C blockingMappedReduced(Iterator begin, - Iterator end, - MapFunctor map, - T (C::*reduce)(U), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<typename MapFunctor::result_type, C> - (begin, - end, - map, - QtConcurrent::MemberFunctionWrapper1<T, C, U>(reduce), + return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> + (begin, end, + QtPrivate::createFunctionWrapper(map), + QtPrivate::createFunctionWrapper(reduce), options) .startBlocking(); } -template <typename ResultType, typename Iterator, typename T, typename U, typename ReduceFunctor> -ResultType blockingMappedReduced(Iterator begin, +template <typename Iterator, typename MapFunctor, typename ReduceFunctor> +typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(Iterator begin, Iterator end, - T (map)(U), - ReduceFunctor reduce, - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<T, ResultType> - (begin, - end, - QtConcurrent::FunctionWrapper1<T, U>(map), - reduce, - options) - .startBlocking(); -} - -template <typename ResultType, typename Iterator, typename T, typename C, typename ReduceFunctor> -ResultType blockingMappedReduced(Iterator begin, - Iterator end, - T (C::*map)() const, + MapFunctor map, ReduceFunctor reduce, QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) { - return QtConcurrent::startMappedReduced<T, ResultType> - (begin, - end, - QtConcurrent::ConstMemberFunctionWrapper<T, C>(map), - reduce, - options) - .startBlocking(); -} - -template <typename Iterator, typename T, typename U, typename V, typename W, typename X> -W blockingMappedReduced(Iterator begin, - Iterator end, - T (map)(U), - V (reduce)(W &, X), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<T, W> - (begin, - end, - QtConcurrent::FunctionWrapper1<T, U>(map), - QtConcurrent::FunctionWrapper2<V, W &, X>(reduce), - options) - .startBlocking(); -} - -template <typename Iterator, typename T, typename C, typename U, typename V, typename W> -V blockingMappedReduced(Iterator begin, - Iterator end, - T (C::*map)() const, - U (reduce)(V &, W), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<T, V> - (begin, - end, - QtConcurrent::ConstMemberFunctionWrapper<T, C>(map), - QtConcurrent::FunctionWrapper2<U, V &, W>(reduce), - options) - .startBlocking(); -} - -template <typename Iterator, typename T, typename U, typename V, typename C, typename W> -C blockingMappedReduced(Iterator begin, - Iterator end, - T (map)(U), - V (C::*reduce)(W), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<T, C> - (begin, - end, - QtConcurrent::FunctionWrapper1<T, U>(map), - QtConcurrent::MemberFunctionWrapper1<V, C, W>(reduce), - options) - .startBlocking(); -} - -template <typename Iterator, typename T, typename C, typename U,typename D, typename V> -D blockingMappedReduced(Iterator begin, - Iterator end, - T (C::*map)() const, - U (D::*reduce)(V), - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<T, D> - (begin, - end, - QtConcurrent::ConstMemberFunctionWrapper<T, C>(map), - QtConcurrent::MemberFunctionWrapper1<U, D, V>(reduce), + return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> + (begin, end, + QtPrivate::createFunctionWrapper(map), + QtPrivate::createFunctionWrapper(reduce), options) .startBlocking(); } @@ -675,97 +268,44 @@ D blockingMappedReduced(Iterator begin, template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence blockingMapped(const InputSequence &sequence, MapFunctor map) { - return blockingMappedReduced(sequence, map, &OutputSequence::push_back, - QtConcurrent::OrderedReduce); -} - -template <typename OutputSequence, typename InputSequence, typename T, typename U> -OutputSequence blockingMapped(const InputSequence &sequence, T (map)(U)) -{ - return blockingMappedReduced(sequence, map, &OutputSequence::push_back, - QtConcurrent::OrderedReduce); -} - -template <typename OutputSequence, typename InputSequence, typename T, typename C> -OutputSequence blockingMapped(const InputSequence &sequence, T (C::*map)() const) -{ - return blockingMappedReduced(sequence, map, &OutputSequence::push_back, - QtConcurrent::OrderedReduce); -} -#ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS - -// overloads for changing the container value type: -template <template <typename> class Sequence, typename MapFunctor, typename T> -Sequence<typename MapFunctor::result_type> blockingMapped(const Sequence<T> &sequence, MapFunctor map) -{ - typedef Sequence<typename MapFunctor::result_type> OutputSequence; - return blockingMappedReduced(sequence, map, &OutputSequence::push_back, - QtConcurrent::OrderedReduce); -} - -template <template <typename> class Sequence, typename T, typename U, typename V> -Sequence<U> blockingMapped(const Sequence<T> &sequence, U (map)(V)) -{ - typedef Sequence<U> OutputSequence; - return blockingMappedReduced(sequence, map, &OutputSequence::push_back, - QtConcurrent::OrderedReduce); -} - -template <template <typename> class Sequence, typename T, typename U, typename C> -Sequence<U> blockingMapped(const Sequence<T> &sequence, U (C::*map)() const) -{ - typedef Sequence<U> OutputSequence; - return blockingMappedReduced(sequence, map, &OutputSequence::push_back, - QtConcurrent::OrderedReduce); -} - -#endif // QT_NO_TEMPLATE_TEMPLATE_PARAMETER - -// overloads for changing the container value type from a QStringList: -template <typename MapFunctor> -QList<typename MapFunctor::result_type> blockingMapped(const QStringList &sequence, MapFunctor map) -{ - typedef QList<typename MapFunctor::result_type> OutputSequence; - return blockingMappedReduced(sequence, map, &OutputSequence::push_back, - QtConcurrent::OrderedReduce); -} - -template <typename U, typename V> -QList<U> blockingMapped(const QStringList &sequence, U (map)(V)) -{ - typedef QList<U> OutputSequence; - return blockingMappedReduced(sequence, map, &OutputSequence::push_back, - QtConcurrent::OrderedReduce); + return blockingMappedReduced<OutputSequence> + (sequence, + QtPrivate::createFunctionWrapper(map), + &OutputSequence::push_back, + QtConcurrent::OrderedReduce); } -template <typename U, typename C> -QList<U> blockingMapped(const QStringList &sequence, U (C::*map)() const) +template <typename MapFunctor, typename InputSequence> +typename QtPrivate::MapResultType<InputSequence, MapFunctor>::ResultType blockingMapped(const InputSequence &sequence, MapFunctor map) { - typedef QList<U> OutputSequence; - return blockingMappedReduced(sequence, map, &OutputSequence::push_back, - QtConcurrent::OrderedReduce); + typedef typename QtPrivate::MapResultType<InputSequence, MapFunctor>::ResultType OutputSequence; + return blockingMappedReduced<OutputSequence> + (sequence, + QtPrivate::createFunctionWrapper(map), + &OutputSequence::push_back, + QtConcurrent::OrderedReduce); } // mapped() for iterator ranges template <typename Sequence, typename Iterator, typename MapFunctor> Sequence blockingMapped(Iterator begin, Iterator end, MapFunctor map) { - return blockingMappedReduced(begin, end, map, &Sequence::push_back, - QtConcurrent::OrderedReduce); -} - -template <typename Sequence, typename Iterator, typename T, typename U> -Sequence blockingMapped(Iterator begin, Iterator end, T (map)(U)) -{ - return blockingMappedReduced(begin, end, map, &Sequence::push_back, - QtConcurrent::OrderedReduce); + return blockingMappedReduced<Sequence> + (begin, end, + QtPrivate::createFunctionWrapper(map), + &Sequence::push_back, + QtConcurrent::OrderedReduce); } -template <typename Sequence, typename Iterator, typename T, typename C> -Sequence blockingMapped(Iterator begin, Iterator end, T (C::*map)() const) -{ - return blockingMappedReduced(begin, end, map, &Sequence::push_back, - QtConcurrent::OrderedReduce); +template <typename Iterator, typename MapFunctor> +typename QtPrivate::MapResultType<Iterator, MapFunctor>::ResultType blockingMapped(Iterator begin, Iterator end, MapFunctor map) +{ + typedef typename QtPrivate::MapResultType<Iterator, MapFunctor>::ResultType OutputSequence; + return blockingMappedReduced<OutputSequence> + (begin, end, + QtPrivate::createFunctionWrapper(map), + &OutputSequence::push_back, + QtConcurrent::OrderedReduce); } } // namespace QtConcurrent |