llvm-project
530 строк · 27.3 Кб
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TYPE_TRAITS
11#define _LIBCPP_TYPE_TRAITS
12
13/*
14type_traits synopsis
15
16namespace std
17{
18
19// helper class:
20template <class T, T v> struct integral_constant;
21typedef integral_constant<bool, true> true_type; // C++11
22typedef integral_constant<bool, false> false_type; // C++11
23
24template <bool B> // C++14
25using bool_constant = integral_constant<bool, B>; // C++14
26typedef bool_constant<true> true_type; // C++14
27typedef bool_constant<false> false_type; // C++14
28
29// helper traits
30template <bool, class T = void> struct enable_if;
31template <bool, class T, class F> struct conditional;
32
33// Primary classification traits:
34template <class T> struct is_void;
35template <class T> struct is_null_pointer; // C++14
36template <class T> struct is_integral;
37template <class T> struct is_floating_point;
38template <class T> struct is_array;
39template <class T> struct is_pointer;
40template <class T> struct is_lvalue_reference;
41template <class T> struct is_rvalue_reference;
42template <class T> struct is_member_object_pointer;
43template <class T> struct is_member_function_pointer;
44template <class T> struct is_enum;
45template <class T> struct is_union;
46template <class T> struct is_class;
47template <class T> struct is_function;
48
49// Secondary classification traits:
50template <class T> struct is_reference;
51template <class T> struct is_arithmetic;
52template <class T> struct is_fundamental;
53template <class T> struct is_member_pointer;
54template <class T> struct is_scoped_enum; // C++23
55template <class T> struct is_scalar;
56template <class T> struct is_object;
57template <class T> struct is_compound;
58
59// Const-volatile properties and transformations:
60template <class T> struct is_const;
61template <class T> struct is_volatile;
62template <class T> struct remove_const;
63template <class T> struct remove_volatile;
64template <class T> struct remove_cv;
65template <class T> struct add_const;
66template <class T> struct add_volatile;
67template <class T> struct add_cv;
68
69// Reference transformations:
70template <class T> struct remove_reference;
71template <class T> struct add_lvalue_reference;
72template <class T> struct add_rvalue_reference;
73
74// Pointer transformations:
75template <class T> struct remove_pointer;
76template <class T> struct add_pointer;
77
78template<class T> struct type_identity; // C++20
79template<class T>
80using type_identity_t = typename type_identity<T>::type; // C++20
81
82// Integral properties:
83template <class T> struct is_signed;
84template <class T> struct is_unsigned;
85template <class T> struct make_signed;
86template <class T> struct make_unsigned;
87
88// Array properties and transformations:
89template <class T> struct rank;
90template <class T, unsigned I = 0> struct extent;
91template <class T> struct remove_extent;
92template <class T> struct remove_all_extents;
93
94template <class T> struct is_bounded_array; // C++20
95template <class T> struct is_unbounded_array; // C++20
96
97// Member introspection:
98template <class T> struct is_pod;
99template <class T> struct is_trivial;
100template <class T> struct is_trivially_copyable;
101template <class T> struct is_standard_layout;
102template <class T> struct is_literal_type; // Deprecated in C++17; removed in C++20
103template <class T> struct is_empty;
104template <class T> struct is_polymorphic;
105template <class T> struct is_abstract;
106template <class T> struct is_final; // C++14
107template <class T> struct is_aggregate; // C++17
108
109template <class T, class... Args> struct is_constructible;
110template <class T> struct is_default_constructible;
111template <class T> struct is_copy_constructible;
112template <class T> struct is_move_constructible;
113template <class T, class U> struct is_assignable;
114template <class T> struct is_copy_assignable;
115template <class T> struct is_move_assignable;
116template <class T, class U> struct is_swappable_with; // C++17
117template <class T> struct is_swappable; // C++17
118template <class T> struct is_destructible;
119
120template <class T, class... Args> struct is_trivially_constructible;
121template <class T> struct is_trivially_default_constructible;
122template <class T> struct is_trivially_copy_constructible;
123template <class T> struct is_trivially_move_constructible;
124template <class T, class U> struct is_trivially_assignable;
125template <class T> struct is_trivially_copy_assignable;
126template <class T> struct is_trivially_move_assignable;
127template <class T> struct is_trivially_destructible;
128
129template <class T, class... Args> struct is_nothrow_constructible;
130template <class T> struct is_nothrow_default_constructible;
131template <class T> struct is_nothrow_copy_constructible;
132template <class T> struct is_nothrow_move_constructible;
133template <class T, class U> struct is_nothrow_assignable;
134template <class T> struct is_nothrow_copy_assignable;
135template <class T> struct is_nothrow_move_assignable;
136template <class T, class U> struct is_nothrow_swappable_with; // C++17
137template <class T> struct is_nothrow_swappable; // C++17
138template <class T> struct is_nothrow_destructible;
139
140template <class T> struct has_virtual_destructor;
141
142template<class T> struct has_unique_object_representations; // C++17
143
144// Relationships between types:
145template <class T, class U> struct is_same;
146template <class Base, class Derived> struct is_base_of;
147
148template <class From, class To> struct is_convertible;
149template <typename From, typename To> struct is_nothrow_convertible; // C++20
150template <typename From, typename To> inline constexpr bool is_nothrow_convertible_v; // C++20
151
152template <class Fn, class... ArgTypes> struct is_invocable;
153template <class R, class Fn, class... ArgTypes> struct is_invocable_r;
154
155template <class Fn, class... ArgTypes> struct is_nothrow_invocable;
156template <class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r;
157
158// Alignment properties and transformations:
159template <class T> struct alignment_of;
160template <size_t Len, size_t Align = most_stringent_alignment_requirement>
161struct aligned_storage; // deprecated in C++23
162template <size_t Len, class... Types> struct aligned_union; // deprecated in C++23
163template <class T> struct remove_cvref; // C++20
164
165template <class T> struct decay;
166template <class... T> struct common_type;
167template <class T> struct underlying_type;
168template <class> class result_of; // undefined; deprecated in C++17; removed in C++20
169template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>; // deprecated in C++17; removed in C++20
170template <class Fn, class... ArgTypes> struct invoke_result; // C++17
171
172// const-volatile modifications:
173template <class T>
174using remove_const_t = typename remove_const<T>::type; // C++14
175template <class T>
176using remove_volatile_t = typename remove_volatile<T>::type; // C++14
177template <class T>
178using remove_cv_t = typename remove_cv<T>::type; // C++14
179template <class T>
180using add_const_t = typename add_const<T>::type; // C++14
181template <class T>
182using add_volatile_t = typename add_volatile<T>::type; // C++14
183template <class T>
184using add_cv_t = typename add_cv<T>::type; // C++14
185
186// reference modifications:
187template <class T>
188using remove_reference_t = typename remove_reference<T>::type; // C++14
189template <class T>
190using add_lvalue_reference_t = typename add_lvalue_reference<T>::type; // C++14
191template <class T>
192using add_rvalue_reference_t = typename add_rvalue_reference<T>::type; // C++14
193
194// sign modifications:
195template <class T>
196using make_signed_t = typename make_signed<T>::type; // C++14
197template <class T>
198using make_unsigned_t = typename make_unsigned<T>::type; // C++14
199
200// array modifications:
201template <class T>
202using remove_extent_t = typename remove_extent<T>::type; // C++14
203template <class T>
204using remove_all_extents_t = typename remove_all_extents<T>::type; // C++14
205
206template <class T>
207inline constexpr bool is_bounded_array_v
208= is_bounded_array<T>::value; // C++20
209inline constexpr bool is_unbounded_array_v
210= is_unbounded_array<T>::value; // C++20
211
212// pointer modifications:
213template <class T>
214using remove_pointer_t = typename remove_pointer<T>::type; // C++14
215template <class T>
216using add_pointer_t = typename add_pointer<T>::type; // C++14
217
218// other transformations:
219template <size_t Len, size_t Align=default-alignment>
220using aligned_storage_t = typename aligned_storage<Len,Align>::type; // C++14
221template <size_t Len, class... Types>
222using aligned_union_t = typename aligned_union<Len,Types...>::type; // C++14
223template <class T>
224using remove_cvref_t = typename remove_cvref<T>::type; // C++20
225template <class T>
226using decay_t = typename decay<T>::type; // C++14
227template <bool b, class T=void>
228using enable_if_t = typename enable_if<b,T>::type; // C++14
229template <bool b, class T, class F>
230using conditional_t = typename conditional<b,T,F>::type; // C++14
231template <class... T>
232using common_type_t = typename common_type<T...>::type; // C++14
233template <class T>
234using underlying_type_t = typename underlying_type<T>::type; // C++14
235template <class T>
236using result_of_t = typename result_of<T>::type; // C++14; deprecated in C++17; removed in C++20
237template <class Fn, class... ArgTypes>
238using invoke_result_t = typename invoke_result<Fn, ArgTypes...>::type; // C++17
239
240template <class...>
241using void_t = void; // C++17
242
243// See C++14 20.10.4.1, primary type categories
244template <class T> inline constexpr bool is_void_v
245= is_void<T>::value; // C++17
246template <class T> inline constexpr bool is_null_pointer_v
247= is_null_pointer<T>::value; // C++17
248template <class T> inline constexpr bool is_integral_v
249= is_integral<T>::value; // C++17
250template <class T> inline constexpr bool is_floating_point_v
251= is_floating_point<T>::value; // C++17
252template <class T> inline constexpr bool is_array_v
253= is_array<T>::value; // C++17
254template <class T> inline constexpr bool is_pointer_v
255= is_pointer<T>::value; // C++17
256template <class T> inline constexpr bool is_lvalue_reference_v
257= is_lvalue_reference<T>::value; // C++17
258template <class T> inline constexpr bool is_rvalue_reference_v
259= is_rvalue_reference<T>::value; // C++17
260template <class T> inline constexpr bool is_member_object_pointer_v
261= is_member_object_pointer<T>::value; // C++17
262template <class T> inline constexpr bool is_member_function_pointer_v
263= is_member_function_pointer<T>::value; // C++17
264template <class T> inline constexpr bool is_enum_v
265= is_enum<T>::value; // C++17
266template <class T> inline constexpr bool is_union_v
267= is_union<T>::value; // C++17
268template <class T> inline constexpr bool is_class_v
269= is_class<T>::value; // C++17
270template <class T> inline constexpr bool is_function_v
271= is_function<T>::value; // C++17
272
273// See C++14 20.10.4.2, composite type categories
274template <class T> inline constexpr bool is_reference_v
275= is_reference<T>::value; // C++17
276template <class T> inline constexpr bool is_arithmetic_v
277= is_arithmetic<T>::value; // C++17
278template <class T> inline constexpr bool is_fundamental_v
279= is_fundamental<T>::value; // C++17
280template <class T> inline constexpr bool is_object_v
281= is_object<T>::value; // C++17
282template <class T> inline constexpr bool is_scalar_v
283= is_scalar<T>::value; // C++17
284template <class T> inline constexpr bool is_compound_v
285= is_compound<T>::value; // C++17
286template <class T> inline constexpr bool is_member_pointer_v
287= is_member_pointer<T>::value; // C++17
288template <class T> inline constexpr bool is_scoped_enum_v
289= is_scoped_enum<T>::value; // C++23
290
291// See C++14 20.10.4.3, type properties
292template <class T> inline constexpr bool is_const_v
293= is_const<T>::value; // C++17
294template <class T> inline constexpr bool is_volatile_v
295= is_volatile<T>::value; // C++17
296template <class T> inline constexpr bool is_trivial_v
297= is_trivial<T>::value; // C++17
298template <class T> inline constexpr bool is_trivially_copyable_v
299= is_trivially_copyable<T>::value; // C++17
300template <class T> inline constexpr bool is_standard_layout_v
301= is_standard_layout<T>::value; // C++17
302template <class T> inline constexpr bool is_pod_v
303= is_pod<T>::value; // C++17
304template <class T> inline constexpr bool is_literal_type_v
305= is_literal_type<T>::value; // C++17; deprecated in C++17; removed in C++20
306template <class T> inline constexpr bool is_empty_v
307= is_empty<T>::value; // C++17
308template <class T> inline constexpr bool is_polymorphic_v
309= is_polymorphic<T>::value; // C++17
310template <class T> inline constexpr bool is_abstract_v
311= is_abstract<T>::value; // C++17
312template <class T> inline constexpr bool is_final_v
313= is_final<T>::value; // C++17
314template <class T> inline constexpr bool is_aggregate_v
315= is_aggregate<T>::value; // C++17
316template <class T> inline constexpr bool is_signed_v
317= is_signed<T>::value; // C++17
318template <class T> inline constexpr bool is_unsigned_v
319= is_unsigned<T>::value; // C++17
320template <class T, class... Args> inline constexpr bool is_constructible_v
321= is_constructible<T, Args...>::value; // C++17
322template <class T> inline constexpr bool is_default_constructible_v
323= is_default_constructible<T>::value; // C++17
324template <class T> inline constexpr bool is_copy_constructible_v
325= is_copy_constructible<T>::value; // C++17
326template <class T> inline constexpr bool is_move_constructible_v
327= is_move_constructible<T>::value; // C++17
328template <class T, class U> inline constexpr bool is_assignable_v
329= is_assignable<T, U>::value; // C++17
330template <class T> inline constexpr bool is_copy_assignable_v
331= is_copy_assignable<T>::value; // C++17
332template <class T> inline constexpr bool is_move_assignable_v
333= is_move_assignable<T>::value; // C++17
334template <class T, class U> inline constexpr bool is_swappable_with_v
335= is_swappable_with<T, U>::value; // C++17
336template <class T> inline constexpr bool is_swappable_v
337= is_swappable<T>::value; // C++17
338template <class T> inline constexpr bool is_destructible_v
339= is_destructible<T>::value; // C++17
340template <class T, class... Args> inline constexpr bool is_trivially_constructible_v
341= is_trivially_constructible<T, Args...>::value; // C++17
342template <class T> inline constexpr bool is_trivially_default_constructible_v
343= is_trivially_default_constructible<T>::value; // C++17
344template <class T> inline constexpr bool is_trivially_copy_constructible_v
345= is_trivially_copy_constructible<T>::value; // C++17
346template <class T> inline constexpr bool is_trivially_move_constructible_v
347= is_trivially_move_constructible<T>::value; // C++17
348template <class T, class U> inline constexpr bool is_trivially_assignable_v
349= is_trivially_assignable<T, U>::value; // C++17
350template <class T> inline constexpr bool is_trivially_copy_assignable_v
351= is_trivially_copy_assignable<T>::value; // C++17
352template <class T> inline constexpr bool is_trivially_move_assignable_v
353= is_trivially_move_assignable<T>::value; // C++17
354template <class T> inline constexpr bool is_trivially_destructible_v
355= is_trivially_destructible<T>::value; // C++17
356template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v
357= is_nothrow_constructible<T, Args...>::value; // C++17
358template <class T> inline constexpr bool is_nothrow_default_constructible_v
359= is_nothrow_default_constructible<T>::value; // C++17
360template <class T> inline constexpr bool is_nothrow_copy_constructible_v
361= is_nothrow_copy_constructible<T>::value; // C++17
362template <class T> inline constexpr bool is_nothrow_move_constructible_v
363= is_nothrow_move_constructible<T>::value; // C++17
364template <class T, class U> inline constexpr bool is_nothrow_assignable_v
365= is_nothrow_assignable<T, U>::value; // C++17
366template <class T> inline constexpr bool is_nothrow_copy_assignable_v
367= is_nothrow_copy_assignable<T>::value; // C++17
368template <class T> inline constexpr bool is_nothrow_move_assignable_v
369= is_nothrow_move_assignable<T>::value; // C++17
370template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v
371= is_nothrow_swappable_with<T, U>::value; // C++17
372template <class T> inline constexpr bool is_nothrow_swappable_v
373= is_nothrow_swappable<T>::value; // C++17
374template <class T> inline constexpr bool is_nothrow_destructible_v
375= is_nothrow_destructible<T>::value; // C++17
376template <class T> inline constexpr bool has_virtual_destructor_v
377= has_virtual_destructor<T>::value; // C++17
378template<class T> inline constexpr bool has_unique_object_representations_v // C++17
379= has_unique_object_representations<T>::value;
380
381// See C++14 20.10.5, type property queries
382template <class T> inline constexpr size_t alignment_of_v
383= alignment_of<T>::value; // C++17
384template <class T> inline constexpr size_t rank_v
385= rank<T>::value; // C++17
386template <class T, unsigned I = 0> inline constexpr size_t extent_v
387= extent<T, I>::value; // C++17
388
389// See C++14 20.10.6, type relations
390template <class T, class U> inline constexpr bool is_same_v
391= is_same<T, U>::value; // C++17
392template <class Base, class Derived> inline constexpr bool is_base_of_v
393= is_base_of<Base, Derived>::value; // C++17
394template <class From, class To> inline constexpr bool is_convertible_v
395= is_convertible<From, To>::value; // C++17
396template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v
397= is_invocable<Fn, ArgTypes...>::value; // C++17
398template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v
399= is_invocable_r<R, Fn, ArgTypes...>::value; // C++17
400template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v
401= is_nothrow_invocable<Fn, ArgTypes...>::value; // C++17
402template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v
403= is_nothrow_invocable_r<R, Fn, ArgTypes...>::value; // C++17
404
405// [meta.logical], logical operator traits:
406template<class... B> struct conjunction; // C++17
407template<class... B>
408inline constexpr bool conjunction_v = conjunction<B...>::value; // C++17
409template<class... B> struct disjunction; // C++17
410template<class... B>
411inline constexpr bool disjunction_v = disjunction<B...>::value; // C++17
412template<class B> struct negation; // C++17
413template<class B>
414inline constexpr bool negation_v = negation<B>::value; // C++17
415
416}
417
418*/
419
420#include <__config>
421#include <__fwd/functional.h> // This is https://llvm.org/PR56938
422#include <__type_traits/add_const.h>
423#include <__type_traits/add_cv.h>
424#include <__type_traits/add_lvalue_reference.h>
425#include <__type_traits/add_pointer.h>
426#include <__type_traits/add_rvalue_reference.h>
427#include <__type_traits/add_volatile.h>
428#include <__type_traits/aligned_storage.h>
429#include <__type_traits/aligned_union.h>
430#include <__type_traits/alignment_of.h>
431#include <__type_traits/can_extract_key.h>
432#include <__type_traits/common_reference.h>
433#include <__type_traits/common_type.h>
434#include <__type_traits/conditional.h>
435#include <__type_traits/conjunction.h>
436#include <__type_traits/decay.h>
437#include <__type_traits/dependent_type.h>
438#include <__type_traits/disjunction.h>
439#include <__type_traits/enable_if.h>
440#include <__type_traits/extent.h>
441#include <__type_traits/has_unique_object_representation.h>
442#include <__type_traits/has_virtual_destructor.h>
443#include <__type_traits/integral_constant.h>
444#include <__type_traits/invoke.h>
445#include <__type_traits/is_abstract.h>
446#include <__type_traits/is_aggregate.h>
447#include <__type_traits/is_arithmetic.h>
448#include <__type_traits/is_array.h>
449#include <__type_traits/is_assignable.h>
450#include <__type_traits/is_base_of.h>
451#include <__type_traits/is_bounded_array.h>
452#include <__type_traits/is_callable.h>
453#include <__type_traits/is_char_like_type.h>
454#include <__type_traits/is_class.h>
455#include <__type_traits/is_compound.h>
456#include <__type_traits/is_const.h>
457#include <__type_traits/is_constant_evaluated.h>
458#include <__type_traits/is_constructible.h>
459#include <__type_traits/is_convertible.h>
460#include <__type_traits/is_destructible.h>
461#include <__type_traits/is_empty.h>
462#include <__type_traits/is_enum.h>
463#include <__type_traits/is_final.h>
464#include <__type_traits/is_floating_point.h>
465#include <__type_traits/is_function.h>
466#include <__type_traits/is_fundamental.h>
467#include <__type_traits/is_implicitly_default_constructible.h>
468#include <__type_traits/is_integral.h>
469#include <__type_traits/is_literal_type.h>
470#include <__type_traits/is_member_function_pointer.h>
471#include <__type_traits/is_member_object_pointer.h>
472#include <__type_traits/is_member_pointer.h>
473#include <__type_traits/is_nothrow_assignable.h>
474#include <__type_traits/is_nothrow_constructible.h>
475#include <__type_traits/is_nothrow_convertible.h>
476#include <__type_traits/is_nothrow_destructible.h>
477#include <__type_traits/is_null_pointer.h>
478#include <__type_traits/is_object.h>
479#include <__type_traits/is_pod.h>
480#include <__type_traits/is_pointer.h>
481#include <__type_traits/is_polymorphic.h>
482#include <__type_traits/is_reference.h>
483#include <__type_traits/is_reference_wrapper.h>
484#include <__type_traits/is_referenceable.h>
485#include <__type_traits/is_same.h>
486#include <__type_traits/is_scalar.h>
487#include <__type_traits/is_scoped_enum.h>
488#include <__type_traits/is_signed.h>
489#include <__type_traits/is_specialization.h>
490#include <__type_traits/is_standard_layout.h>
491#include <__type_traits/is_swappable.h>
492#include <__type_traits/is_trivial.h>
493#include <__type_traits/is_trivially_assignable.h>
494#include <__type_traits/is_trivially_constructible.h>
495#include <__type_traits/is_trivially_copyable.h>
496#include <__type_traits/is_trivially_destructible.h>
497#include <__type_traits/is_unbounded_array.h>
498#include <__type_traits/is_union.h>
499#include <__type_traits/is_unsigned.h>
500#include <__type_traits/is_void.h>
501#include <__type_traits/is_volatile.h>
502#include <__type_traits/make_const_lvalue_ref.h>
503#include <__type_traits/make_signed.h>
504#include <__type_traits/make_unsigned.h>
505#include <__type_traits/maybe_const.h>
506#include <__type_traits/negation.h>
507#include <__type_traits/rank.h>
508#include <__type_traits/remove_all_extents.h>
509#include <__type_traits/remove_const.h>
510#include <__type_traits/remove_const_ref.h>
511#include <__type_traits/remove_cv.h>
512#include <__type_traits/remove_extent.h>
513#include <__type_traits/remove_pointer.h>
514#include <__type_traits/remove_reference.h>
515#include <__type_traits/remove_volatile.h>
516#include <__type_traits/result_of.h>
517#include <__type_traits/type_identity.h>
518#include <__type_traits/underlying_type.h>
519#include <__type_traits/unwrap_ref.h>
520#include <__type_traits/void_t.h>
521#include <__utility/declval.h>
522#include <cstddef>
523#include <cstdint>
524#include <version>
525
526#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
527# pragma GCC system_header
528#endif
529
530#endif // _LIBCPP_TYPE_TRAITS
531