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