Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtconcurrentfunctionwrappers.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QTCONCURRENT_FUNCTIONWRAPPERS_H
6#define QTCONCURRENT_FUNCTIONWRAPPERS_H
7
8#include <QtConcurrent/qtconcurrentcompilertest.h>
9#include <QtConcurrent/qtconcurrentreducekernel.h>
10#include <QtCore/qfuture.h>
11
12#include <tuple>
13
14#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
15
16QT_BEGIN_NAMESPACE
17
18namespace QtPrivate {
19
21{
22 template <class C, class U>
23 inline void operator()(C &c, const U &u) const
24 {
25 return c.push_back(u);
26 }
27
28 template <class C, class U>
29 inline void operator()(C &c, U &&u) const
30 {
31 return c.push_back(u);
32 }
33};
34
35// -- MapResultType
36
37template <class T, class Enable = void>
39{
40 using Type = void;
41};
42
43template <class Sequence>
45{
46 using Type = std::decay_t<decltype(*std::declval<Sequence>().begin())>;
47};
48
49template <class Iterator>
51{
52 using Type = std::decay_t<decltype(*std::declval<Iterator>())>;
53};
54
55template <class T>
56using ArgumentType = typename Argument<T>::Type;
57
58template <class T, class MapFunctor>
60{
62 "It's not possible to invoke the function with passed argument.");
64};
65
66template <class T, class MapFunctor>
67using MapResultType = typename MapResult<T, MapFunctor>::Type;
68
69// -- ReduceResultType
70
71template <class T>
73
74template <class U, class V>
75struct ReduceResultType<void(*)(U&,V)>
76{
77 using ResultType = U;
78};
79
80template <class T, class C, class U>
81struct ReduceResultType<T(C::*)(U)>
82{
83 using ResultType = C;
84};
85
86template <class U, class V>
87struct ReduceResultType<std::function<void(U&, V)>>
88{
89 using ResultType = U;
90};
91
92template <typename R, typename ...A>
93struct ReduceResultType<R(*)(A...)>
94{
95 using ResultType = typename std::tuple_element<0, std::tuple<A...>>::type;
96};
97
98template <class U, class V>
99struct ReduceResultType<void(*)(U&,V) noexcept>
100{
101 using ResultType = U;
102};
103
104template <class T, class C, class U>
105struct ReduceResultType<T(C::*)(U) noexcept>
106{
107 using ResultType = C;
108};
109
110template<class T, class Enable = void>
111inline constexpr bool hasCallOperator_v = false;
112
113template<class T>
114inline constexpr bool hasCallOperator_v<T, std::void_t<decltype(&T::operator())>> = true;
115
116template<class T, class Enable = void>
117inline constexpr bool isIterator_v = false;
118
119template<class T>
120inline constexpr bool isIterator_v<T, std::void_t<typename std::iterator_traits<T>::value_type>> =
121 true;
122
123template <class Callable, class Sequence>
125
126template <class InitialValueType, class ResultType>
130
131template<class Callable, class Enable = void>
133{
134};
135
136template <class Callable>
143
144template <class Callable>
151
152// -- MapSequenceResultType
153
154template <class InputSequence, class MapFunctor>
156{
157 static_assert(std::is_same_v<typename InputSequence::value_type,
159 "Couldn't deduce the output sequence type, you must specify it explicitly.");
160 typedef InputSequence ResultType;
161};
162
163#ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
164
165template <template <typename...> class InputSequence, typename MapFunctor, typename ...T>
166struct MapSequenceResultType<InputSequence<T...>, MapFunctor>
167{
169};
170
171#endif // QT_NO_TEMPLATE_TEMPLATE_PARAMETER
172
173} // namespace QtPrivate.
174
175
176QT_END_NAMESPACE
177
178#endif // QT_NO_CONCURRENT
179
180#endif
constexpr bool hasCallOperator_v
constexpr bool isInitialValueCompatible_v
typename MapResult< T, MapFunctor >::Type MapResultType
constexpr bool isIterator_v
InputSequence< QtPrivate::MapResultType< InputSequence< T... >, MapFunctor > > ResultType
void operator()(C &c, const U &u) const
typename std::tuple_element< 0, std::tuple< A... > >::type ResultType