576 lines · plain
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP_TYPE_TRAITS11#define _LIBCPP_TYPE_TRAITS12 13/*14 type_traits synopsis15 16namespace std17{18 19 // helper class:20 template <class T, T v> struct integral_constant;21 typedef integral_constant<bool, true> true_type; // since C++1122 typedef integral_constant<bool, false> false_type; // since C++1123 24 template <bool B>25 using bool_constant = integral_constant<bool, B>; // since C++1726 27 // helper traits28 template <bool, class T = void> struct enable_if;29 template <bool, class T, class F> struct conditional;30 31 // Primary classification traits:32 template <class T> struct is_void;33 template <class T> struct is_null_pointer; // since C++1434 template <class T> struct is_integral;35 template <class T> struct is_floating_point;36 template <class T> struct is_array;37 template <class T> struct is_pointer;38 template <class T> struct is_lvalue_reference;39 template <class T> struct is_rvalue_reference;40 template <class T> struct is_member_object_pointer;41 template <class T> struct is_member_function_pointer;42 template <class T> struct is_enum;43 template <class T> struct is_union;44 template <class T> struct is_class;45 template <class T> struct is_function;46 47 // Secondary classification traits:48 template <class T> struct is_reference;49 template <class T> struct is_arithmetic;50 template <class T> struct is_fundamental;51 template <class T> struct is_member_pointer;52 template <class T> struct is_scoped_enum; // since C++2353 template <class T> struct is_scalar;54 template <class T> struct is_object;55 template <class T> struct is_compound;56 57 // Const-volatile properties and transformations:58 template <class T> struct is_const;59 template <class T> struct is_volatile;60 template <class T> struct remove_const;61 template <class T> struct remove_volatile;62 template <class T> struct remove_cv;63 template <class T> struct add_const;64 template <class T> struct add_volatile;65 template <class T> struct add_cv;66 67 // Reference transformations:68 template <class T> struct remove_reference;69 template <class T> struct add_lvalue_reference;70 template <class T> struct add_rvalue_reference;71 72 // Pointer transformations:73 template <class T> struct remove_pointer;74 template <class T> struct add_pointer;75 76 template<class T> struct type_identity; // since C++2077 template<class T>78 using type_identity_t = typename type_identity<T>::type; // since C++2079 80 // Integral properties:81 template <class T> struct is_signed;82 template <class T> struct is_unsigned;83 template <class T> struct make_signed;84 template <class T> struct make_unsigned;85 86 // Array properties and transformations:87 template <class T> struct rank;88 template <class T, unsigned I = 0> struct extent;89 template <class T> struct remove_extent;90 template <class T> struct remove_all_extents;91 92 template <class T> struct is_bounded_array; // since C++2093 template <class T> struct is_unbounded_array; // since C++2094 95 // Member introspection:96 template <class T> struct is_trivial; // deprecated in C++2697 template <class T> struct is_pod; // deprecated in C++2098 template <class T> struct is_trivially_copyable;99 template <class T> struct is_standard_layout;100 template <class T> struct is_literal_type; // deprecated in C++17; removed in C++20101 template <class T> struct is_empty;102 template <class T> struct is_polymorphic;103 template <class T> struct is_abstract;104 template <class T> struct is_final; // since C++14105 template <class T> struct is_aggregate; // since C++17106 107 template <class T, class... Args> struct is_constructible;108 template <class T> struct is_default_constructible;109 template <class T> struct is_copy_constructible;110 template <class T> struct is_move_constructible;111 template <class T, class U> struct is_assignable;112 template <class T> struct is_copy_assignable;113 template <class T> struct is_move_assignable;114 template <class T, class U> struct is_swappable_with; // since C++17115 template <class T> struct is_swappable; // since C++17116 template <class T> struct is_destructible;117 118 template <class T, class... Args> struct is_trivially_constructible;119 template <class T> struct is_trivially_default_constructible;120 template <class T> struct is_trivially_copy_constructible;121 template <class T> struct is_trivially_move_constructible;122 template <class T, class U> struct is_trivially_assignable;123 template <class T> struct is_trivially_copy_assignable;124 template <class T> struct is_trivially_move_assignable;125 template <class T> struct is_trivially_destructible;126 127 template <class T, class... Args> struct is_nothrow_constructible;128 template <class T> struct is_nothrow_default_constructible;129 template <class T> struct is_nothrow_copy_constructible;130 template <class T> struct is_nothrow_move_constructible;131 template <class T, class U> struct is_nothrow_assignable;132 template <class T> struct is_nothrow_copy_assignable;133 template <class T> struct is_nothrow_move_assignable;134 template <class T, class U>135 struct is_nothrow_swappable_with; // since C++17136 template <class T>137 struct is_nothrow_swappable; // since C++17138 template <class T> struct is_nothrow_destructible;139 140 template <class T> struct is_implicit_lifetime; // since C++23141 142 template <class T> struct has_virtual_destructor;143 144 template <class T>145 struct has_unique_object_representations; // since C++17146 147 template<class T, class U>148 struct reference_constructs_from_temporary; // since C++23149 template<class T, class U>150 struct reference_converts_from_temporary; // since C++23151 152 // Relationships between types:153 template <class T, class U> struct is_same;154 template <class Base, class Derived> struct is_base_of;155 template <class Base, class Derived>156 struct is_virtual_base_of; // since C++26157 158 template <class From, class To> struct is_convertible;159 template <class From, class To>160 struct is_nothrow_convertible; // since C++20161 162 template <class Fn, class... ArgTypes> struct is_invocable; // since C++17163 template <class R, class Fn, class... ArgTypes>164 struct is_invocable_r; // since C++17165 166 template <class Fn, class... ArgTypes>167 struct is_nothrow_invocable; // since C++17168 template <class R, class Fn, class... ArgTypes>169 struct is_nothrow_invocable_r; // since C++17170 171 // Alignment properties and transformations:172 template <class T> struct alignment_of;173 template <size_t Len, size_t Align = most_stringent_alignment_requirement>174 struct aligned_storage; // deprecated in C++23175 template <size_t Len, class... Types> struct aligned_union; // deprecated in C++23176 template <class T> struct remove_cvref; // since C++20177 178 template <class T> struct decay;179 template <class... T> struct common_type;180 template <class T> struct underlying_type;181 template <class> struct result_of; // undefined; deprecated in C++17; removed in C++20182 template <class Fn, class... ArgTypes>183 struct result_of<Fn(ArgTypes...)>; // deprecated in C++17; removed in C++20184 template <class Fn, class... ArgTypes>185 struct invoke_result; // since C++17186 187 // const-volatile modifications:188 template <class T>189 using remove_const_t = typename remove_const<T>::type; // since C++14190 template <class T>191 using remove_volatile_t192 = typename remove_volatile<T>::type; // since C++14193 template <class T>194 using remove_cv_t = typename remove_cv<T>::type; // since C++14195 template <class T>196 using add_const_t = typename add_const<T>::type; // since C++14197 template <class T>198 using add_volatile_t = typename add_volatile<T>::type; // since C++14199 template <class T>200 using add_cv_t = typename add_cv<T>::type; // since C++14201 202 // reference modifications:203 template <class T>204 using remove_reference_t205 = typename remove_reference<T>::type; // since C++14206 template <class T>207 using add_lvalue_reference_t208 = typename add_lvalue_reference<T>::type; // since C++14209 template <class T>210 using add_rvalue_reference_t211 = typename add_rvalue_reference<T>::type; // since C++14212 213 // sign modifications:214 template <class T>215 using make_signed_t = typename make_signed<T>::type; // since C++14216 template <class T>217 using make_unsigned_t = typename make_unsigned<T>::type; // since C++14218 219 // array modifications:220 template <class T>221 using remove_extent_t222 = typename remove_extent<T>::type; // since C++14223 template <class T>224 using remove_all_extents_t225 = typename remove_all_extents<T>::type; // since C++14226 227 template <class T>228 inline constexpr bool is_bounded_array_v229 = is_bounded_array<T>::value; // since C++20230 inline constexpr bool is_unbounded_array_v231 = is_unbounded_array<T>::value; // since C++20232 233 // pointer modifications:234 template <class T>235 using remove_pointer_t236 = typename remove_pointer<T>::type; // since C++14237 template <class T>238 using add_pointer_t = typename add_pointer<T>::type; // since C++14239 240 // other transformations:241 template <size_t Len, size_t Align=default-alignment>242 using aligned_storage_t243 = typename aligned_storage<Len,Align>::type; // since C++14244 template <size_t Len, class... Types>245 using aligned_union_t246 = typename aligned_union<Len,Types...>::type; // since C++14247 template <class T>248 using remove_cvref_t249 = typename remove_cvref<T>::type; // since C++20250 template <class T>251 using decay_t = typename decay<T>::type; // since C++14252 template <bool b, class T=void>253 using enable_if_t = typename enable_if<b,T>::type; // since C++14254 template <bool b, class T, class F>255 using conditional_t256 = typename conditional<b,T,F>::type; // since C++14257 template <class... T>258 using common_type_t259 = typename common_type<T...>::type; // since C++14260 template <class T>261 using underlying_type_t262 = typename underlying_type<T>::type; // since C++14263 template <class T>264 using result_of_t = typename result_of<T>::type; // since C++14; deprecated in C++17; removed in C++20265 template <class Fn, class... ArgTypes>266 using invoke_result_t267 = typename invoke_result<Fn, ArgTypes...>::type; // since C++17268 269 template <class...>270 using void_t = void; // since C++17271 272 // See C++14 20.10.4.1, primary type categories273 template <class T> inline constexpr bool is_void_v274 = is_void<T>::value; // since C++17275 template <class T> inline constexpr bool is_null_pointer_v276 = is_null_pointer<T>::value; // since C++17277 template <class T> inline constexpr bool is_integral_v278 = is_integral<T>::value; // since C++17279 template <class T> inline constexpr bool is_floating_point_v280 = is_floating_point<T>::value; // since C++17281 template <class T> inline constexpr bool is_array_v282 = is_array<T>::value; // since C++17283 template <class T> inline constexpr bool is_pointer_v284 = is_pointer<T>::value; // since C++17285 template <class T> inline constexpr bool is_lvalue_reference_v286 = is_lvalue_reference<T>::value; // since C++17287 template <class T> inline constexpr bool is_rvalue_reference_v288 = is_rvalue_reference<T>::value; // since C++17289 template <class T> inline constexpr bool is_member_object_pointer_v290 = is_member_object_pointer<T>::value; // since C++17291 template <class T> inline constexpr bool is_member_function_pointer_v292 = is_member_function_pointer<T>::value; // since C++17293 template <class T> inline constexpr bool is_enum_v294 = is_enum<T>::value; // since C++17295 template <class T> inline constexpr bool is_union_v296 = is_union<T>::value; // since C++17297 template <class T> inline constexpr bool is_class_v298 = is_class<T>::value; // since C++17299 template <class T> inline constexpr bool is_function_v300 = is_function<T>::value; // since C++17301 302 // See C++14 20.10.4.2, composite type categories303 template <class T> inline constexpr bool is_reference_v304 = is_reference<T>::value; // since C++17305 template <class T> inline constexpr bool is_arithmetic_v306 = is_arithmetic<T>::value; // since C++17307 template <class T> inline constexpr bool is_fundamental_v308 = is_fundamental<T>::value; // since C++17309 template <class T> inline constexpr bool is_object_v310 = is_object<T>::value; // since C++17311 template <class T> inline constexpr bool is_scalar_v312 = is_scalar<T>::value; // since C++17313 template <class T> inline constexpr bool is_compound_v314 = is_compound<T>::value; // since C++17315 template <class T> inline constexpr bool is_member_pointer_v316 = is_member_pointer<T>::value; // since C++17317 template <class T> inline constexpr bool is_scoped_enum_v318 = is_scoped_enum<T>::value; // since C++23319 320 // See C++14 20.10.4.3, type properties321 template <class T> inline constexpr bool is_const_v322 = is_const<T>::value; // since C++17323 template <class T> inline constexpr bool is_volatile_v324 = is_volatile<T>::value; // since C++17325 template <class T> inline constexpr bool is_trivial_v326 = is_trivial<T>::value; // since C++17; deprecated in C++26327 template <class T> inline constexpr bool is_trivially_copyable_v328 = is_trivially_copyable<T>::value; // since C++17329 template <class T> inline constexpr bool is_standard_layout_v330 = is_standard_layout<T>::value; // since C++17331 template <class T> inline constexpr bool is_pod_v332 = is_pod<T>::value; // since C++17; deprecated in C++20333 template <class T> inline constexpr bool is_literal_type_v334 = is_literal_type<T>::value; // since C++17; deprecated in C++17; removed in C++20335 template <class T> inline constexpr bool is_empty_v336 = is_empty<T>::value; // since C++17337 template <class T> inline constexpr bool is_polymorphic_v338 = is_polymorphic<T>::value; // since C++17339 template <class T> inline constexpr bool is_abstract_v340 = is_abstract<T>::value; // since C++17341 template <class T> inline constexpr bool is_final_v342 = is_final<T>::value; // since C++17343 template <class T> inline constexpr bool is_aggregate_v344 = is_aggregate<T>::value; // since C++17345 template <class T> inline constexpr bool is_signed_v346 = is_signed<T>::value; // since C++17347 template <class T> inline constexpr bool is_unsigned_v348 = is_unsigned<T>::value; // since C++17349 template <class T, class... Args> inline constexpr bool is_constructible_v350 = is_constructible<T, Args...>::value; // since C++17351 template <class T> inline constexpr bool is_default_constructible_v352 = is_default_constructible<T>::value; // since C++17353 template <class T> inline constexpr bool is_copy_constructible_v354 = is_copy_constructible<T>::value; // since C++17355 template <class T> inline constexpr bool is_move_constructible_v356 = is_move_constructible<T>::value; // since C++17357 template <class T, class U> inline constexpr bool is_assignable_v358 = is_assignable<T, U>::value; // since C++17359 template <class T> inline constexpr bool is_copy_assignable_v360 = is_copy_assignable<T>::value; // since C++17361 template <class T> inline constexpr bool is_move_assignable_v362 = is_move_assignable<T>::value; // since C++17363 template <class T, class U> inline constexpr bool is_swappable_with_v364 = is_swappable_with<T, U>::value; // since C++17365 template <class T> inline constexpr bool is_swappable_v366 = is_swappable<T>::value; // since C++17367 template <class T> inline constexpr bool is_destructible_v368 = is_destructible<T>::value; // since C++17369 template <class T, class... Args> inline constexpr bool is_trivially_constructible_v370 = is_trivially_constructible<T, Args...>::value; // since C++17371 template <class T> inline constexpr bool is_trivially_default_constructible_v372 = is_trivially_default_constructible<T>::value; // since C++17373 template <class T> inline constexpr bool is_trivially_copy_constructible_v374 = is_trivially_copy_constructible<T>::value; // since C++17375 template <class T> inline constexpr bool is_trivially_move_constructible_v376 = is_trivially_move_constructible<T>::value; // since C++17377 template <class T, class U> inline constexpr bool is_trivially_assignable_v378 = is_trivially_assignable<T, U>::value; // since C++17379 template <class T> inline constexpr bool is_trivially_copy_assignable_v380 = is_trivially_copy_assignable<T>::value; // since C++17381 template <class T> inline constexpr bool is_trivially_move_assignable_v382 = is_trivially_move_assignable<T>::value; // since C++17383 template <class T> inline constexpr bool is_trivially_destructible_v384 = is_trivially_destructible<T>::value; // since C++17385 template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v386 = is_nothrow_constructible<T, Args...>::value; // since C++17387 template <class T> inline constexpr bool is_nothrow_default_constructible_v388 = is_nothrow_default_constructible<T>::value; // since C++17389 template <class T> inline constexpr bool is_nothrow_copy_constructible_v390 = is_nothrow_copy_constructible<T>::value; // since C++17391 template <class T> inline constexpr bool is_nothrow_move_constructible_v392 = is_nothrow_move_constructible<T>::value; // since C++17393 template <class T, class U> inline constexpr bool is_nothrow_assignable_v394 = is_nothrow_assignable<T, U>::value; // since C++17395 template <class T> inline constexpr bool is_nothrow_copy_assignable_v396 = is_nothrow_copy_assignable<T>::value; // since C++17397 template <class T> inline constexpr bool is_nothrow_move_assignable_v398 = is_nothrow_move_assignable<T>::value; // since C++17399 template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v400 = is_nothrow_swappable_with<T, U>::value; // since C++17401 template <class T> inline constexpr bool is_nothrow_swappable_v402 = is_nothrow_swappable<T>::value; // since C++17403 template <class T> inline constexpr bool is_nothrow_destructible_v404 = is_nothrow_destructible<T>::value; // since C++17405 template <class T> inline constexpr bool is_implicit_lifetime_v406 = is_implicit_lifetime<T>::value; // since C++23407 template <class T> inline constexpr bool has_virtual_destructor_v408 = has_virtual_destructor<T>::value; // since C++17409 template<class T> inline constexpr bool has_unique_object_representations_v410 = has_unique_object_representations<T>::value; // since C++17411 template<class T, class U>412 constexpr bool reference_constructs_from_temporary_v413 = reference_constructs_from_temporary<T, U>::value; // since C++23414 template<class T, class U>415 constexpr bool reference_converts_from_temporary_v416 = reference_converts_from_temporary<T, U>::value; // since C++23417 418 // See C++14 20.10.5, type property queries419 template <class T> inline constexpr size_t alignment_of_v420 = alignment_of<T>::value; // since C++17421 template <class T> inline constexpr size_t rank_v422 = rank<T>::value; // since C++17423 template <class T, unsigned I = 0> inline constexpr size_t extent_v424 = extent<T, I>::value; // since C++17425 426 // See C++14 20.10.6, type relations427 template <class T, class U> inline constexpr bool is_same_v428 = is_same<T, U>::value; // since C++17429 template <class Base, class Derived> inline constexpr bool is_base_of_v430 = is_base_of<Base, Derived>::value; // since C++17431 template <class Base, class Derived> inline constexpr bool is_virtual_base_of_v432 = is_virtual_base_of<Base, Derived>::value; // since C++26433 template <class From, class To> inline constexpr bool is_convertible_v434 = is_convertible<From, To>::value; // since C++17435 template <class From, class To> inline constexpr bool is_nothrow_convertible_v436 = is_nothrow_convertible<From, To>::value; // since C++20437 template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v438 = is_invocable<Fn, ArgTypes...>::value; // since C++17439 template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v440 = is_invocable_r<R, Fn, ArgTypes...>::value; // since C++17441 template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v442 = is_nothrow_invocable<Fn, ArgTypes...>::value; // since C++17443 template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v444 = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value; // since C++17445 446 // [meta.logical], logical operator traits:447 template<class... B> struct conjunction; // since C++17448 template<class... B> inline constexpr bool conjunction_v449 = conjunction<B...>::value; // since C++17450 template<class... B> struct disjunction; // since C++17451 template<class... B> inline constexpr bool disjunction_v452 = disjunction<B...>::value; // since C++17453 template<class B> struct negation; // since C++17454 template<class B> inline constexpr bool negation_v455 = negation<B>::value; // since C++17456 457 // [meta.const.eval], constant evaluation context458 constexpr bool is_constant_evaluated() noexcept; // C++20459 template<class T>460 consteval bool is_within_lifetime(const T*) noexcept; // C++26461}462 463*/464 465#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)466# include <__cxx03/type_traits>467#else468# include <__config>469# include <__type_traits/add_cv_quals.h>470# include <__type_traits/add_pointer.h>471# include <__type_traits/add_reference.h>472# include <__type_traits/aligned_storage.h>473# include <__type_traits/aligned_union.h>474# include <__type_traits/alignment_of.h>475# include <__type_traits/common_type.h>476# include <__type_traits/conditional.h>477# include <__type_traits/decay.h>478# include <__type_traits/enable_if.h>479# include <__type_traits/extent.h>480# include <__type_traits/has_virtual_destructor.h>481# include <__type_traits/integral_constant.h>482# include <__type_traits/is_abstract.h>483# include <__type_traits/is_arithmetic.h>484# include <__type_traits/is_array.h>485# include <__type_traits/is_assignable.h>486# include <__type_traits/is_base_of.h>487# include <__type_traits/is_class.h>488# include <__type_traits/is_compound.h>489# include <__type_traits/is_const.h>490# include <__type_traits/is_constructible.h>491# include <__type_traits/is_convertible.h>492# include <__type_traits/is_destructible.h>493# include <__type_traits/is_empty.h>494# include <__type_traits/is_enum.h>495# include <__type_traits/is_floating_point.h>496# include <__type_traits/is_function.h>497# include <__type_traits/is_fundamental.h>498# include <__type_traits/is_integral.h>499# include <__type_traits/is_literal_type.h>500# include <__type_traits/is_member_pointer.h>501# include <__type_traits/is_nothrow_assignable.h>502# include <__type_traits/is_nothrow_constructible.h>503# include <__type_traits/is_nothrow_destructible.h>504# include <__type_traits/is_object.h>505# include <__type_traits/is_pod.h>506# include <__type_traits/is_pointer.h>507# include <__type_traits/is_polymorphic.h>508# include <__type_traits/is_reference.h>509# include <__type_traits/is_same.h>510# include <__type_traits/is_scalar.h>511# include <__type_traits/is_signed.h>512# include <__type_traits/is_standard_layout.h>513# include <__type_traits/is_trivial.h>514# include <__type_traits/is_trivially_assignable.h>515# include <__type_traits/is_trivially_constructible.h>516# include <__type_traits/is_trivially_copyable.h>517# include <__type_traits/is_trivially_destructible.h>518# include <__type_traits/is_union.h>519# include <__type_traits/is_unsigned.h>520# include <__type_traits/is_void.h>521# include <__type_traits/is_volatile.h>522# include <__type_traits/make_signed.h>523# include <__type_traits/make_unsigned.h>524# include <__type_traits/rank.h>525# include <__type_traits/remove_all_extents.h>526# include <__type_traits/remove_const.h>527# include <__type_traits/remove_cv.h>528# include <__type_traits/remove_extent.h>529# include <__type_traits/remove_pointer.h>530# include <__type_traits/remove_reference.h>531# include <__type_traits/remove_volatile.h>532# include <__type_traits/result_of.h>533# include <__type_traits/underlying_type.h>534 535# if _LIBCPP_STD_VER >= 14536# include <__type_traits/is_final.h>537# include <__type_traits/is_null_pointer.h>538# endif539 540# if _LIBCPP_STD_VER >= 17541# include <__type_traits/conjunction.h>542# include <__type_traits/disjunction.h>543# include <__type_traits/has_unique_object_representation.h>544# include <__type_traits/invoke.h>545# include <__type_traits/is_aggregate.h>546# include <__type_traits/is_swappable.h>547# include <__type_traits/negation.h>548# include <__type_traits/void_t.h>549# endif550 551# if _LIBCPP_STD_VER >= 20552# include <__type_traits/common_reference.h>553# include <__type_traits/is_constant_evaluated.h>554# include <__type_traits/type_identity.h>555# include <__type_traits/unwrap_ref.h>556# endif557 558# if _LIBCPP_STD_VER >= 23559# include <__type_traits/is_implicit_lifetime.h>560# include <__type_traits/reference_constructs_from_temporary.h>561# include <__type_traits/reference_converts_from_temporary.h>562# endif563 564# if _LIBCPP_STD_VER >= 26565# include <__type_traits/is_within_lifetime.h>566# endif567 568# include <version>569 570# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)571# pragma GCC system_header572# endif573#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)574 575#endif // _LIBCPP_TYPE_TRAITS576