File: logical_metafunctions.h

package info (click to toggle)
libthrust 1.17.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,900 kB
  • sloc: ansic: 29,519; cpp: 23,989; python: 1,421; sh: 811; perl: 460; makefile: 112
file content (287 lines) | stat: -rw-r--r-- 7,888 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
 *  Copyright 2008-2021 NVIDIA Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/*! \file
 *  \brief C++17's
 *  <a href="https://en.cppreference.com/w/cpp/types/conjunction"><tt>std::conjunction</tt></a>,
 *  <a href="https://en.cppreference.com/w/cpp/types/disjunction"><tt>std::disjunction</tt></a>,
 *  and <a href="https://en.cppreference.com/w/cpp/types/negation"><tt>std::negation</tt></a>
 *  metafunctions and related extensions.
 */

#pragma once

#include <thrust/detail/config.h>
#include <thrust/detail/cpp11_required.h>

#if THRUST_CPP_DIALECT >= 2011

#include <type_traits>

THRUST_NAMESPACE_BEGIN

/*! \addtogroup utility
 *  \{
 */

/*! \addtogroup type_traits Type Traits
 *  \{
 */

/*! \brief <a href="https://en.cppreference.com/w/cpp/types/integral_constant"><tt>std::integral_constant</tt></a>
 *  whose value is <tt>(... && Ts::value)</tt>.
 *
 *  \see conjunction_v
 *  \see conjunction_value
 *  \see <a href="https://en.cppreference.com/w/cpp/types/conjunction"><tt>std::conjunction</tt></a>
 */
#if THRUST_CPP_DIALECT >= 2017
template <typename... Ts>
using conjunction = std::conjunction<Ts...>;
#else // Older than C++17.
template <typename... Ts>
struct conjunction;

/*! \cond
 */

template <>
struct conjunction<> : std::true_type {};

template <typename T>
struct conjunction<T> : T {};

template <typename T0, typename T1>
struct conjunction<T0, T1> : std::conditional<T0::value, T1, T0>::type {};

template<typename T0, typename T1, typename T2, typename... TN>
struct conjunction<T0, T1, T2, TN...>
  : std::conditional<T0::value, conjunction<T1, T2, TN...>, T0>::type {};

/*! \endcond
 */
#endif

/*! \brief <tt>constexpr bool</tt> whose value is <tt>(... && Ts::value)</tt>.
 *
 *  \see conjunction
 *  \see conjunction_value
 *  \see <a href="https://en.cppreference.com/w/cpp/types/conjunction"><tt>std::conjunction</tt></a>
 */
#if THRUST_CPP_DIALECT >= 2014
template <typename... Ts>
constexpr bool conjunction_v = conjunction<Ts...>::value;
#endif

/*! \brief <a href="https://en.cppreference.com/w/cpp/types/integral_constant"><tt>std::integral_constant</tt></a>
 *  whose value is <tt>(... || Ts::value)</tt>.
 *
 *  \see disjunction_v
 *  \see disjunction_value
 *  \see <a href="https://en.cppreference.com/w/cpp/types/disjunction"><tt>std::disjunction</tt></a>
 */
#if THRUST_CPP_DIALECT >= 2017
template <typename... Ts>
using disjunction = std::disjunction<Ts...>;
#else // Older than C++17.
template <typename... Ts>
struct disjunction;

/*! \cond
 */

template <>
struct disjunction<> : std::false_type {};

template <typename T>
struct disjunction<T> : T {};

template <typename T0, typename... TN>
struct disjunction<T0, TN...>
  : std::conditional<T0::value != false, T0, disjunction<TN...> >::type {};

/*! \endcond
 */
#endif

/*! \brief <tt>constexpr bool</tt> whose value is <tt>(... || Ts::value)</tt>.
 *
 *  \see disjunction
 *  \see disjunction_value
 *  \see <a href="https://en.cppreference.com/w/cpp/types/disjunction"><tt>std::disjunction</tt></a>
 */
#if THRUST_CPP_DIALECT >= 2014
template <typename... Ts>
constexpr bool disjunction_v = disjunction<Ts...>::value;
#endif

/*! \brief <a href="https://en.cppreference.com/w/cpp/types/integral_constant"><tt>std::integral_constant</tt></a>
 *  whose value is <tt>!Ts::value</tt>.
 *
 *  \see negation_v
 *  \see negation_value
 *  \see <a href="https://en.cppreference.com/w/cpp/types/negation"><tt>std::negation</tt></a>
 */
#if THRUST_CPP_DIALECT >= 2017
template <typename T>
using negation = std::negation<T>;
#else // Older than C++17.
template <typename T>
struct negation;

/*! \cond
 */

template <typename T>
struct negation : std::integral_constant<bool, !T::value> {};

/*! \endcond
 */
#endif

/*! \brief <tt>constexpr bool</tt> whose value is <tt>!Ts::value</tt>.
 *
 *  \see negation
 *  \see negation_value
 *  \see <a href="https://en.cppreference.com/w/cpp/types/negation"><tt>std::negation</tt></a>
 */
#if THRUST_CPP_DIALECT >= 2014
template <typename T>
constexpr bool negation_v = negation<T>::value;
#endif

///////////////////////////////////////////////////////////////////////////////

/*! \brief <a href="https://en.cppreference.com/w/cpp/types/integral_constant"><tt>std::integral_constant</tt></a>
 *  whose value is <tt>(... && Bs)</tt>.
 *
 *  \see conjunction_value_v
 *  \see conjunction
 *  \see <a href="https://en.cppreference.com/w/cpp/types/conjunction"><tt>std::conjunction</tt></a>
 */
template <bool... Bs>
struct conjunction_value;

#if THRUST_CPP_DIALECT >= 2014
/*! \brief <tt>constexpr bool</tt> whose value is <tt>(... && Bs)</tt>.
 *
 *  \see conjunction_value
 *  \see conjunction
 *  \see <a href="https://en.cppreference.com/w/cpp/types/conjunction"><tt>std::conjunction</tt></a>
 */
template <bool... Bs>
constexpr bool conjunction_value_v = conjunction_value<Bs...>::value;
#endif

/*! \cond
 */

template <>
struct conjunction_value<> : std::true_type {};

template <bool B>
struct conjunction_value<B> : std::integral_constant<bool, B> {};

template <bool B, bool... Bs>
struct conjunction_value<B, Bs...>
  : std::integral_constant<bool, B && conjunction_value<Bs...>::value> {};

/*! \endcond
 */

///////////////////////////////////////////////////////////////////////////////

/*! \brief <a href="https://en.cppreference.com/w/cpp/types/integral_constant"><tt>std::integral_constant</tt></a>
 *  whose value is <tt>(... || Bs)</tt>.
 *
 *  \see disjunction_value_v
 *  \see disjunction
 *  \see <a href="https://en.cppreference.com/w/cpp/types/disjunction"><tt>std::disjunction</tt></a>
 */
template <bool... Bs>
struct disjunction_value;

#if THRUST_CPP_DIALECT >= 2014
/*! \brief <tt>constexpr bool</tt> whose value is <tt>(... || Bs)</tt>.
 *
 *  \see disjunction_value
 *  \see disjunction
 *  \see <a href="https://en.cppreference.com/w/cpp/types/disjunction"><tt>std::disjunction</tt></a>
 */
template <bool... Bs>
constexpr bool disjunction_value_v = disjunction_value<Bs...>::value;
#endif

/*! \cond
 */

template <>
struct disjunction_value<> : std::false_type {};

template <bool B>
struct disjunction_value<B> : std::integral_constant<bool, B> {};

template <bool B, bool... Bs>
struct disjunction_value<B, Bs...>
  : std::integral_constant<bool, B || disjunction_value<Bs...>::value> {};

/*! \endcond
 */

///////////////////////////////////////////////////////////////////////////////

/*! \brief <a href="https://en.cppreference.com/w/cpp/types/integral_constant"><tt>std::integral_constant</tt></a>
 *  whose value is <tt>!Bs</tt>.
 *
 *  \see negation_value_v
 *  \see negation
 *  \see <a href="https://en.cppreference.com/w/cpp/types/negation"><tt>std::negation</tt></a>
 */
template <bool B>
struct negation_value;

#if THRUST_CPP_DIALECT >= 2014
/*! \brief <tt>constexpr bool</tt> whose value is <tt>!Ts::value</tt>.
 *
 *  \see negation_value
 *  \see negation
 *  \see <a href="https://en.cppreference.com/w/cpp/types/negation"><tt>std::negation</tt></a>
 */
template <bool B>
constexpr bool negation_value_v = negation_value<B>::value;
#endif

/*! \cond
 */

template <bool B>
struct negation_value : std::integral_constant<bool, !B> {};

/*! \endcond
 */

///////////////////////////////////////////////////////////////////////////////

/*! \} // type traits
 */

/*! \} // utility
 */

THRUST_NAMESPACE_END

#endif // THRUST_CPP_DIALECT >= 2011