libstdc++
experimental/type_traits
Go to the documentation of this file.
1// Variable Templates For Type Traits -*- C++ -*-
2
3// Copyright (C) 2014-2020 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file experimental/type_traits
26 * This is a TS C++ Library header.
27 * @ingroup libfund-ts
28 */
29
30//
31// N3932 Variable Templates For Type Traits (Revision 1)
32//
33
34#ifndef _GLIBCXX_EXPERIMENTAL_TYPE_TRAITS
35#define _GLIBCXX_EXPERIMENTAL_TYPE_TRAITS 1
36
37#pragma GCC system_header
38
39#if __cplusplus >= 201402L
40
41#include <type_traits>
43
44namespace std _GLIBCXX_VISIBILITY(default)
45{
46_GLIBCXX_BEGIN_NAMESPACE_VERSION
47
48namespace experimental
49{
50inline namespace fundamentals_v1
51{
52#define __cpp_lib_experimental_type_trait_variable_templates 201402
53
54// See C++14 20.10.4.1, primary type categories
55template <typename _Tp>
56 constexpr bool is_void_v = is_void<_Tp>::value;
57template <typename _Tp>
58 constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value;
59template <typename _Tp>
60 constexpr bool is_integral_v = is_integral<_Tp>::value;
61template <typename _Tp>
62 constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
63template <typename _Tp>
64 constexpr bool is_array_v = is_array<_Tp>::value;
65template <typename _Tp>
66 constexpr bool is_pointer_v = is_pointer<_Tp>::value;
67template <typename _Tp>
68 constexpr bool is_lvalue_reference_v = is_lvalue_reference<_Tp>::value;
69template <typename _Tp>
70 constexpr bool is_rvalue_reference_v = is_rvalue_reference<_Tp>::value;
71template <typename _Tp>
72 constexpr bool is_member_object_pointer_v =
73 is_member_object_pointer<_Tp>::value;
74template <typename _Tp>
75 constexpr bool is_member_function_pointer_v =
76 is_member_function_pointer<_Tp>::value;
77template <typename _Tp>
78 constexpr bool is_enum_v = is_enum<_Tp>::value;
79template <typename _Tp>
80 constexpr bool is_union_v = is_union<_Tp>::value;
81template <typename _Tp>
82 constexpr bool is_class_v = is_class<_Tp>::value;
83template <typename _Tp>
84 constexpr bool is_function_v = is_function<_Tp>::value;
85
86// See C++14 20.10.4.2, composite type categories
87template <typename _Tp>
88 constexpr bool is_reference_v = is_reference<_Tp>::value;
89template <typename _Tp>
90 constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
91template <typename _Tp>
92 constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
93template <typename _Tp>
94 constexpr bool is_object_v = is_object<_Tp>::value;
95template <typename _Tp>
96 constexpr bool is_scalar_v = is_scalar<_Tp>::value;
97template <typename _Tp>
98 constexpr bool is_compound_v = is_compound<_Tp>::value;
99template <typename _Tp>
100 constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
101
102// See C++14 20.10.4.3, type properties
103template <typename _Tp>
104 constexpr bool is_const_v = is_const<_Tp>::value;
105template <typename _Tp>
106 constexpr bool is_volatile_v = is_volatile<_Tp>::value;
107template <typename _Tp>
108 constexpr bool is_trivial_v = is_trivial<_Tp>::value;
109template <typename _Tp>
110 constexpr bool is_trivially_copyable_v = is_trivially_copyable<_Tp>::value;
111template <typename _Tp>
112 constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value;
113#pragma GCC diagnostic push
114#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
115template <typename _Tp>
116 constexpr bool is_pod_v = is_pod<_Tp>::value;
117#pragma GCC diagnostic pop
118template <typename _Tp>
119 constexpr bool is_literal_type_v = is_literal_type<_Tp>::value;
120template <typename _Tp>
121 constexpr bool is_empty_v = is_empty<_Tp>::value;
122template <typename _Tp>
123 constexpr bool is_polymorphic_v = is_polymorphic<_Tp>::value;
124template <typename _Tp>
125 constexpr bool is_abstract_v = is_abstract<_Tp>::value;
126template <typename _Tp>
127 constexpr bool is_final_v = is_final<_Tp>::value;
128template <typename _Tp>
129 constexpr bool is_signed_v = is_signed<_Tp>::value;
130template <typename _Tp>
131 constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
132template <typename _Tp, typename... _Args>
133 constexpr bool is_constructible_v = is_constructible<_Tp, _Args...>::value;
134template <typename _Tp>
135 constexpr bool is_default_constructible_v =
136 is_default_constructible<_Tp>::value;
137template <typename _Tp>
138 constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value;
139template <typename _Tp>
140 constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value;
141template <typename _Tp, typename _Up>
142 constexpr bool is_assignable_v = is_assignable<_Tp, _Up>::value;
143template <typename _Tp>
144 constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
145template <typename _Tp>
146 constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
147template <typename _Tp>
148 constexpr bool is_destructible_v = is_destructible<_Tp>::value;
149template <typename _Tp, typename... _Args>
150 constexpr bool is_trivially_constructible_v =
151 is_trivially_constructible<_Tp, _Args...>::value;
152template <typename _Tp>
153 constexpr bool is_trivially_default_constructible_v =
154 is_trivially_default_constructible<_Tp>::value;
155template <typename _Tp>
156 constexpr bool is_trivially_copy_constructible_v =
157 is_trivially_copy_constructible<_Tp>::value;
158template <typename _Tp>
159 constexpr bool is_trivially_move_constructible_v =
160 is_trivially_move_constructible<_Tp>::value;
161template <typename _Tp, typename _Up>
162 constexpr bool is_trivially_assignable_v =
163 is_trivially_assignable<_Tp, _Up>::value;
164template <typename _Tp>
165 constexpr bool is_trivially_copy_assignable_v =
166 is_trivially_copy_assignable<_Tp>::value;
167template <typename _Tp>
168 constexpr bool is_trivially_move_assignable_v =
169 is_trivially_move_assignable<_Tp>::value;
170template <typename _Tp>
171 constexpr bool is_trivially_destructible_v =
172 is_trivially_destructible<_Tp>::value;
173template <typename _Tp, typename... _Args>
174 constexpr bool is_nothrow_constructible_v =
175 is_nothrow_constructible<_Tp, _Args...>::value;
176template <typename _Tp>
177 constexpr bool is_nothrow_default_constructible_v =
178 is_nothrow_default_constructible<_Tp>::value;
179template <typename _Tp>
180 constexpr bool is_nothrow_copy_constructible_v =
181 is_nothrow_copy_constructible<_Tp>::value;
182template <typename _Tp>
183 constexpr bool is_nothrow_move_constructible_v =
184 is_nothrow_move_constructible<_Tp>::value;
185template <typename _Tp, typename _Up>
186 constexpr bool is_nothrow_assignable_v =
187 is_nothrow_assignable<_Tp, _Up>::value;
188template <typename _Tp>
189 constexpr bool is_nothrow_copy_assignable_v =
190 is_nothrow_copy_assignable<_Tp>::value;
191template <typename _Tp>
192 constexpr bool is_nothrow_move_assignable_v =
193 is_nothrow_move_assignable<_Tp>::value;
194template <typename _Tp>
195 constexpr bool is_nothrow_destructible_v =
196 is_nothrow_destructible<_Tp>::value;
197template <typename _Tp>
198 constexpr bool has_virtual_destructor_v =
199 has_virtual_destructor<_Tp>::value;
200
201// See C++14 20.10.5, type property queries
202template <typename _Tp>
203 constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
204template <typename _Tp>
205 constexpr size_t rank_v = rank<_Tp>::value;
206template <typename _Tp, unsigned _Idx = 0>
207 constexpr size_t extent_v = extent<_Tp, _Idx>::value;
208
209// See C++14 20.10.6, type relations
210template <typename _Tp, typename _Up>
211 constexpr bool is_same_v = is_same<_Tp, _Up>::value;
212template <typename _Base, typename _Derived>
213 constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value;
214template <typename _From, typename _To>
215 constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
216
217
218 // 3.3.2, Other type transformations
219 // invocation_type (still unimplemented)
220 // raw_invocation_type (still unimplemented)
221 // invocation_type_t (still unimplemented)
222 // raw_invocation_type_t (still unimplemented)
223} // namespace fundamentals_v1
224
225inline namespace fundamentals_v2
226{
227#define __cpp_lib_experimental_detect 201505
228
229// [meta.detect]
230
231template<typename...> using void_t = void;
232
233#pragma GCC diagnostic push
234#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
235struct __nonesuchbase {};
236struct nonesuch : private __nonesuchbase
237{
238 ~nonesuch() = delete;
239 nonesuch(nonesuch const&) = delete;
240 void operator=(nonesuch const&) = delete;
241};
242#pragma GCC diagnostic pop
243
244template<template<typename...> class _Op, typename... _Args>
245 using is_detected
246 = typename std::__detector<nonesuch, void, _Op, _Args...>::value_t;
247
248template<template<typename...> class _Op, typename... _Args>
249 constexpr bool is_detected_v = is_detected<_Op, _Args...>::value;
250
251template<template<typename...> class _Op, typename... _Args>
252 using detected_t
253 = typename std::__detector<nonesuch, void, _Op, _Args...>::type;
254
255template<typename _Default, template<typename...> class _Op, typename... _Args>
256 using detected_or = std::__detected_or<_Default, _Op, _Args...>;
257
258template<typename _Default, template<typename...> class _Op, typename... _Args>
259 using detected_or_t = typename detected_or<_Default, _Op, _Args...>::type;
260
261template<typename _Expected, template<typename...> class _Op, typename... _Args>
262 using is_detected_exact = is_same<_Expected, detected_t<_Op, _Args...>>;
263
264template<typename _Expected, template<typename...> class _Op, typename... _Args>
265 constexpr bool is_detected_exact_v
266 = is_detected_exact<_Expected, _Op, _Args...>::value;
267
268template<typename _To, template<typename...> class _Op, typename... _Args>
269 using is_detected_convertible
270 = is_convertible<detected_t<_Op, _Args...>, _To>;
271
272template<typename _To, template<typename...> class _Op, typename... _Args>
273 constexpr bool is_detected_convertible_v
274 = is_detected_convertible<_To, _Op, _Args...>::value;
275
276#define __cpp_lib_experimental_logical_traits 201511
277
278template<typename... _Bn>
279 struct conjunction
280 : __and_<_Bn...>
281 { };
282
283template<typename... _Bn>
284 struct disjunction
285 : __or_<_Bn...>
286 { };
287
288template<typename _Pp>
289 struct negation
290 : __not_<_Pp>
291 { };
292
293template<typename... _Bn>
294 constexpr bool conjunction_v
295 = conjunction<_Bn...>::value;
296
297template<typename... _Bn>
298 constexpr bool disjunction_v
299 = disjunction<_Bn...>::value;
300
301template<typename _Pp>
302 constexpr bool negation_v
303 = negation<_Pp>::value;
304} // namespace fundamentals_v2
305} // namespace experimental
306
307_GLIBCXX_END_NAMESPACE_VERSION
308} // namespace std
309
310#endif // __cplusplus <= 201103L
311
312#endif // _GLIBCXX_EXPERIMENTAL_TYPE_TRAITS
void void_t
A metafunction that always yields void, used for detecting valid types.
Definition: type_traits:2563
ISO C++ entities toplevel namespace is std.
Implementation of the detection idiom (negative case).
Definition: type_traits:2570