QtBase  v6.3.1
qtconcurrentfunctionwrappers.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtConcurrent module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QTCONCURRENT_FUNCTIONWRAPPERS_H
41 #define QTCONCURRENT_FUNCTIONWRAPPERS_H
42 
43 #include <QtConcurrent/qtconcurrentcompilertest.h>
44 #include <QtConcurrent/qtconcurrentreducekernel.h>
45 #include <QtCore/qfuture.h>
46 
47 #include <tuple>
48 
49 #if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
50 
52 
53 namespace QtPrivate {
54 
56 {
57  template <class C, class U>
58  inline void operator()(C &c, const U &u) const
59  {
60  return c.push_back(u);
61  }
62 
63  template <class C, class U>
64  inline void operator()(C &c, U &&u) const
65  {
66  return c.push_back(u);
67  }
68 };
69 
70 // -- MapResultType
71 
72 template <class T, class Enable = void>
73 struct Argument
74 {
75  using Type = void;
76 };
77 
78 template <class Sequence>
79 struct Argument<Sequence, typename std::enable_if<IsIterableValue<Sequence>>::type>
80 {
81  using Type = std::decay_t<decltype(*std::declval<Sequence>().begin())>;
82 };
83 
84 template <class Iterator>
85 struct Argument<Iterator, typename std::enable_if<IsDereferenceableValue<Iterator>>::type>
86 {
87  using Type = std::decay_t<decltype(*std::declval<Iterator>())>;
88 };
89 
90 template <class T>
92 
93 template <class T, class MapFunctor>
94 struct MapResult
95 {
96  static_assert(std::is_invocable_v<std::decay_t<MapFunctor>, ArgumentType<T>>,
97  "It's not possible to invoke the function with passed argument.");
98  using Type = std::invoke_result_t<std::decay_t<MapFunctor>, ArgumentType<T>>;
99 };
100 
101 template <class T, class MapFunctor>
103 
104 // -- ReduceResultType
105 
106 template <class T>
108 
109 template <class U, class V>
110 struct ReduceResultType<void(*)(U&,V)>
111 {
112  using ResultType = U;
113 };
114 
115 template <class T, class C, class U>
116 struct ReduceResultType<T(C::*)(U)>
117 {
118  using ResultType = C;
119 };
120 
121 template <class U, class V>
122 struct ReduceResultType<std::function<void(U&, V)>>
123 {
124  using ResultType = U;
125 };
126 
127 template <typename R, typename ...A>
128 struct ReduceResultType<R(*)(A...)>
129 {
130  using ResultType = typename std::tuple_element<0, std::tuple<A...>>::type;
131 };
132 
133 template <class U, class V>
134 struct ReduceResultType<void(*)(U&,V) noexcept>
135 {
136  using ResultType = U;
137 };
138 
139 template <class T, class C, class U>
140 struct ReduceResultType<T(C::*)(U) noexcept>
141 {
142  using ResultType = C;
143 };
144 
145 template<class T, class Enable = void>
146 inline constexpr bool hasCallOperator_v = false;
147 
148 template<class T>
149 inline constexpr bool hasCallOperator_v<T, std::void_t<decltype(&T::operator())>> = true;
150 
151 template<class T, class Enable = void>
152 inline constexpr bool isIterator_v = false;
153 
154 template<class T>
156  true;
157 
158 template <class Callable, class Sequence>
160 
161 template <class InitialValueType, class ResultType>
162 inline constexpr bool isInitialValueCompatible_v = std::conjunction_v<
163  std::is_convertible<InitialValueType, ResultType>,
164  std::negation<std::is_same<std::decay_t<InitialValueType>, QtConcurrent::ReduceOption>>>;
165 
166 template<class Callable, class Enable = void>
168 {
169 };
170 
171 template <class Callable>
173  typename std::enable_if_t<std::is_function_v<std::remove_pointer_t<std::decay_t<Callable>>>
174  || std::is_member_function_pointer_v<std::decay_t<Callable>>>>
175 {
177 };
178 
179 template <class Callable>
181  typename std::enable_if_t<!std::is_function_v<std::remove_pointer_t<std::decay_t<Callable>>>
182  && hasCallOperator_v<std::decay_t<Callable>>>>
183 {
184  using type = std::decay_t<typename QtPrivate::ArgResolver<Callable>::First>;
185 };
186 
187 // -- MapSequenceResultType
188 
189 template <class InputSequence, class MapFunctor>
191 {
192  static_assert(std::is_same_v<typename InputSequence::value_type,
194  "Couldn't deduce the output sequence type, you must specify it explicitly.");
196 };
197 
198 #ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
199 
200 template <template <typename...> class InputSequence, typename MapFunctor, typename ...T>
201 struct MapSequenceResultType<InputSequence<T...>, MapFunctor>
202 {
204 };
205 
206 #endif // QT_NO_TEMPLATE_TEMPLATE_PARAMETER
207 
208 } // namespace QtPrivate.
209 
210 
212 
213 #endif // QT_NO_CONCURRENT
214 
215 #endif
small capitals from c petite p scientific f u
Definition: afcover.h:88
#define T(x)
Definition: main.cpp:42
auto V(a, v))) struct
Definition: hb-algs.hh:317
typename C::value_type value_type
std::is_invocable< Callable, typename std::decay_t< Sequence >::value_type > isInvocable
constexpr bool hasCallOperator_v
constexpr bool isInitialValueCompatible_v
typename MapResult< T, MapFunctor >::Type MapResultType
constexpr bool isIterator_v
typename Argument< T >::Type ArgumentType
def InputSequence(toptions)
Definition: qfloat16.h:381
void
Definition: png.h:1080
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
GLenum type
Definition: qopengl.h:270
const GLubyte * c
Definition: qopenglext.h:12701
std::invoke_result_t< std::decay_t< MapFunctor >, ArgumentType< T > > Type
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
Definition: main.cpp:38
Definition: moc.h:48