標準庫標頭檔案 <type_traits> (C++11)
來自 cppreference.com
此標頭檔案是超程式設計庫的一部分。
類 | ||
輔助類 | ||
(C++11)(C++17) |
指定型別和指定值的編譯時常量 (類模板) | |
true_type
|
std::integral_constant<bool, true> | |
false_type
|
std::integral_constant<bool, false> | |
主要型別類別 (Primary type categories) | ||
(C++11) |
檢查型別是否為 void (類模板) | |
(C++11)(DR*) |
檢查型別是否為 std::nullptr_t (類模板) | |
(C++11) |
檢查型別是否為整型 (類模板) | |
(C++11) |
檢查型別是否為浮點型別 (類模板) | |
(C++11) |
檢查型別是否為陣列型別 (類模板) | |
(C++11) |
檢查一個型別是否是列舉型別 (類模板) | |
(C++11) |
檢查型別是否為聯合型別 (類模板) | |
(C++11) |
檢查型別是否為非聯合類型別 (類模板) | |
(C++11) |
檢查型別是否為函式型別 (類模板) | |
(C++11) |
檢查型別是否為指標型別 (類模板) | |
(C++11) |
檢查型別是否為*左值引用* (類模板) | |
(C++11) |
檢查型別是否為右值引用 (類模板) | |
(C++11) |
檢查型別是否為非靜態成員物件指標 (類模板) | |
(C++11) |
檢查型別是否為非靜態成員函式指標 (類模板) | |
複合型別類別 (Composite type categories) | ||
(C++11) |
檢查型別是否為基本型別 (類模板) | |
(C++11) |
檢查型別是否為算術型別 (類模板) | |
(C++11) |
檢查型別是否為標量型別 (類模板) | |
(C++11) |
檢查型別是否為物件型別 (類模板) | |
(C++11) |
檢查型別是否為複合型別 (類模板) | |
(C++11) |
檢查型別是否為*左值引用*或*右值引用* (類模板) | |
(C++11) |
檢查型別是否為指向非靜態成員函式或物件的指標 (類模板) | |
型別屬性 | ||
(C++11) |
檢查型別是否為 const 限定 (類模板) | |
(C++11) |
檢查型別是否為 volatile 限定 (類模板) | |
(C++11)(C++26 中已棄用) |
檢查型別是否為平凡型別 (類模板) | |
(C++11) |
檢查型別是否為可平凡複製型別 (類模板) | |
(C++11) |
檢查型別是否為標準佈局型別 (類模板) | |
(C++11)(C++20 中已棄用) |
檢查型別是否為純舊資料 (POD) 型別 (類模板) | |
(C++11)(C++17 中已棄用)(C++20 中已移除) |
檢查型別是否為字面型別 (類模板) | |
檢查型別物件表示中的每個位是否都對其值有貢獻 (類模板) | ||
(C++11) |
檢查型別是否為類(而非聯合)型別且沒有非靜態資料成員 (類模板) | |
(C++11) |
檢查型別是否為多型類型別 (類模板) | |
(C++11) |
檢查型別是否為抽象類型別 (類模板) | |
(C++14) |
檢查型別是否為 final 類型別 (類模板) | |
(C++17) |
檢查型別是否為聚合型別 (類模板) | |
(C++23) |
檢查型別是否為隱式生命週期型別 (類模板) | |
(C++11) |
檢查型別是否為有符號算術型別 (類模板) | |
(C++11) |
檢查型別是否為無符號算術型別 (類模板) | |
(C++20) |
檢查型別是否為已知邊界的陣列型別 (類模板) | |
(C++20) |
檢查型別是否為未知邊界的陣列型別 (類模板) | |
(C++23) |
檢查一個型別是否是有作用域的列舉型別 (類模板) |
支援的操作 | |
(C++11)(C++11)(C++11) |
檢查型別是否具有針對特定引數的建構函式 (類模板) |
檢查型別是否具有預設建構函式 (類模板) | |
(C++11)(C++11)(C++11) |
檢查型別是否具有複製建構函式 (類模板) |
(C++11)(C++11)(C++11) |
檢查型別是否可以從右值引用構造 (類模板) |
(C++11)(C++11)(C++11) |
檢查型別是否具有針對特定引數的賦值運算子 (類模板) |
(C++11)(C++11)(C++11) |
檢查型別是否具有複製賦值運算子 (類模板) |
(C++11)(C++11)(C++11) |
檢查型別是否有移動賦值運算子 (類模板) |
(C++11)(C++11)(C++11) |
檢查型別是否具有非刪除的解構函式 (類模板) |
(C++11) |
檢查型別是否具有虛解構函式 (類模板) |
(C++17)(C++17)(C++17)(C++17) |
檢查一種型別的物件是否可以與相同或不同型別的物件進行交換 (類模板) |
檢查引用是否在複製初始化中繫結到臨時物件 (類模板) | |
檢查引用是否在直接初始化中繫結到臨時物件 (類模板) |
屬性查詢 (Property queries) | |
(C++11) |
獲取型別的對齊要求 (類模板) |
(C++11) |
獲取陣列型別的維數 (類模板) |
(C++11) |
獲取陣列型別在指定維度上的大小 (類模板) |
型別關係 | |
(C++11) |
檢查兩個型別是否相同 (類模板) |
(C++11) |
檢查一個型別是否為另一個型別的基類 (類模板) |
(C++26) |
檢查一個型別是否為另一個型別的虛基類 (類模板) |
(C++11)(C++20) |
檢查一個型別是否可以轉換為另一個型別 (類模板) |
(C++20) |
檢查兩個型別是否佈局相容 (類模板) |
檢查一個型別是否為另一個型別的指標可互轉(初始)基類 (類模板) | |
檢查一個型別是否可以使用給定引數型別進行呼叫(如同透過 std::invoke) (類模板) | |
const-volatile 限定符 | |
(C++11)(C++11)(C++11) |
從給定型別中移除 const 和/或 volatile 限定符 (類模板) |
(C++11)(C++11)(C++11) |
向給定型別新增 const 和/或 volatile 限定符 (類模板) |
引用 | |
(C++11) |
從給定型別中移除引用 (類模板) |
(C++11)(C++11) |
向給定型別新增左值或右值引用 (類模板) |
指標 | |
(C++11) |
從給定型別中移除指標 (類模板) |
(C++11) |
向給定型別新增指標 (類模板) |
符號修飾符 | |
(C++11) |
獲取給定整型對應的有符號型別 (類模板) |
(C++11) |
獲取給定整型對應的有符號型別 (類模板) |
陣列 | |
(C++11) |
從給定陣列型別中移除一個維度 (類模板) |
(C++11) |
從給定陣列型別中移除所有維度 (類模板) |
雜項轉換 | |
(自 C++11)(C++23 中已棄用) |
定義適合用作給定大小型別的未初始化儲存的型別 (類模板) |
(自 C++11)(C++23 中已棄用) |
定義適合用作所有給定型別的未初始化儲存的型別 (類模板) |
(C++11) |
當函式引數按值傳遞時應用型別轉換 (類模板) |
(C++20) |
結合了 std::remove_cv 和 std::remove_reference (類模板) |
(C++11) |
有條件地從過載解析中移除函式過載或模板特化 (類模板) |
(C++11) |
根據編譯時布林值選擇一個型別或另一個 (類模板) |
(C++11) |
確定一組型別的公共型別 (類模板) |
確定一組型別的公共引用型別 (類模板) | |
(C++11) |
獲取給定列舉型別的底層整數型別 (類模板) |
(C++11)(C++20 中已移除)(C++17) |
推導呼叫可呼叫物件與一組引數的結果型別 (類模板) |
(C++17) |
void 可變引數別名模板 (別名模板) |
(C++20) |
返回不變的型別引數 (類模板) |
(C++20)(C++20) |
獲取包裝在 std::reference_wrapper 中的引用型別 (類模板) |
對 trait 的操作 | |
(C++17) |
可變引數邏輯 AND 元函式 (類模板) |
(C++17) |
可變引數邏輯 OR 元函式 (類模板) |
(C++17) |
邏輯 NOT 元函式 (類模板) |
函式 | |
成員關係 | |
檢查一個型別的物件是否與該型別的指定子物件指標可互轉 (函式模板) | |
(C++20) |
檢查兩個指定成員在兩個指定型別的公共初始子序列中是否相互對應 (函式模板) |
常量求值上下文 | |
(C++20) |
檢測呼叫是否發生在常量求值上下文內 (函式) |
(C++26) |
檢查指標是否在編譯時處於物件的生命週期內 (函式) |
[編輯] 概要
namespace std { // helper class template<class T, T v> struct integral_constant; template<bool B> using bool_constant = integral_constant<bool, B>; using true_type = bool_constant<true>; using false_type = bool_constant<false>; // primary type categories template<class T> struct is_void; template<class T> struct is_null_pointer; template<class T> struct is_integral; template<class T> struct is_floating_point; template<class T> struct is_array; template<class T> struct is_pointer; template<class T> struct is_lvalue_reference; template<class T> struct is_rvalue_reference; template<class T> struct is_member_object_pointer; template<class T> struct is_member_function_pointer; template<class T> struct is_enum; template<class T> struct is_union; template<class T> struct is_class; template<class T> struct is_function; // composite type categories template<class T> struct is_reference; template<class T> struct is_arithmetic; template<class T> struct is_fundamental; template<class T> struct is_object; template<class T> struct is_scalar; template<class T> struct is_compound; template<class T> struct is_member_pointer; // type properties template<class T> struct is_const; template<class T> struct is_volatile; template<class T> struct is_trivial; template<class T> struct is_trivially_copyable; template<class T> struct is_standard_layout; template<class T> struct is_empty; template<class T> struct is_polymorphic; template<class T> struct is_abstract; template<class T> struct is_final; template<class T> struct is_aggregate; template<class T> struct is_signed; template<class T> struct is_unsigned; template<class T> struct is_bounded_array; template<class T> struct is_unbounded_array; template<class T> struct is_scoped_enum; template<class T, class... Args> struct is_constructible; template<class T> struct is_default_constructible; template<class T> struct is_copy_constructible; template<class T> struct is_move_constructible; template<class T, class U> struct is_assignable; template<class T> struct is_copy_assignable; template<class T> struct is_move_assignable; template<class T, class U> struct is_swappable_with; template<class T> struct is_swappable; template<class T> struct is_destructible; template<class T, class... Args> struct is_trivially_constructible; template<class T> struct is_trivially_default_constructible; template<class T> struct is_trivially_copy_constructible; template<class T> struct is_trivially_move_constructible; template<class T, class U> struct is_trivially_assignable; template<class T> struct is_trivially_copy_assignable; template<class T> struct is_trivially_move_assignable; template<class T> struct is_trivially_destructible; template<class T, class... Args> struct is_nothrow_constructible; template<class T> struct is_nothrow_default_constructible; template<class T> struct is_nothrow_copy_constructible; template<class T> struct is_nothrow_move_constructible; template<class T, class U> struct is_nothrow_assignable; template<class T> struct is_nothrow_copy_assignable; template<class T> struct is_nothrow_move_assignable; template<class T, class U> struct is_nothrow_swappable_with; template<class T> struct is_nothrow_swappable; template<class T> struct is_nothrow_destructible; template<class T> struct has_virtual_destructor; template<class T> struct has_unique_object_representations; template<class T, class U> struct reference_constructs_from_temporary; template<class T, class U> struct reference_converts_from_temporary; // type property queries template<class T> struct alignment_of; template<class T> struct rank; template<class T, unsigned I = 0> struct extent; // type relations template<class T, class U> struct is_same; template<class Base, class Derived> struct is_base_of; template<class Base, class Derived> struct is_virtual_base_of; template<class From, class To> struct is_convertible; template<class From, class To> struct is_nothrow_convertible; template<class T, class U> struct is_layout_compatible; template<class Base, class Derived> struct is_pointer_interconvertible_base_of; template<class Fn, class... ArgTypes> struct is_invocable; template<class R, class Fn, class... ArgTypes> struct is_invocable_r; template<class Fn, class... ArgTypes> struct is_nothrow_invocable; template<class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r; // const-volatile modifications template<class T> struct remove_const; template<class T> struct remove_volatile; template<class T> struct remove_cv; template<class T> struct add_const; template<class T> struct add_volatile; template<class T> struct add_cv; template<class T> using remove_const_t = typename remove_const<T>::type; template<class T> using remove_volatile_t = typename remove_volatile<T>::type; template<class T> using remove_cv_t = typename remove_cv<T>::type; template<class T> using add_const_t = typename add_const<T>::type; template<class T> using add_volatile_t = typename add_volatile<T>::type; template<class T> using add_cv_t = typename add_cv<T>::type; // reference modifications template<class T> struct remove_reference; template<class T> struct add_lvalue_reference; template<class T> struct add_rvalue_reference; template<class T> using remove_reference_t = typename remove_reference<T>::type; template<class T> using add_lvalue_reference_t = typename add_lvalue_reference<T>::type; template<class T> using add_rvalue_reference_t = typename add_rvalue_reference<T>::type; // sign modifications template<class T> struct make_signed; template<class T> struct make_unsigned; template<class T> using make_signed_t = typename make_signed<T>::type; template<class T> using make_unsigned_t = typename make_unsigned<T>::type; // array modifications template<class T> struct remove_extent; template<class T> struct remove_all_extents; template<class T> using remove_extent_t = typename remove_extent<T>::type; template<class T> using remove_all_extents_t = typename remove_all_extents<T>::type; // pointer modifications template<class T> struct remove_pointer; template<class T> struct add_pointer; template<class T> using remove_pointer_t = typename remove_pointer<T>::type; template<class T> using add_pointer_t = typename add_pointer<T>::type; // other transformations template<class T> struct type_identity; template<class T> struct remove_cvref; template<class T> struct decay; template<bool, class T = void> struct enable_if; template<bool, class T, class F> struct conditional; template<class... T> struct common_type; template<class T, class U, template<class> class TQual, template<class> class UQual> struct basic_common_reference { }; template<class... T> struct common_reference; template<class T> struct underlying_type; template<class Fn, class... ArgTypes> struct invoke_result; template<class T> struct unwrap_reference; template<class T> struct unwrap_ref_decay; template<class T> using type_identity_t = typename type_identity<T>::type; template<class T> using remove_cvref_t = typename remove_cvref<T>::type; template<class T> using decay_t = typename decay<T>::type; template<bool b, class T = void> using enable_if_t = typename enable_if<b, T>::type; template<bool b, class T, class F> using conditional_t = typename conditional<b, T, F>::type; template<class... T> using common_type_t = typename common_type<T...>::type; template<class... T> using common_reference_t = typename common_reference<T...>::type; template<class T> using underlying_type_t = typename underlying_type<T>::type; template<class Fn, class... ArgTypes> using invoke_result_t = typename invoke_result<Fn, ArgTypes...>::type; template<class T> using unwrap_reference_t = typename unwrap_reference<T>::type; template<class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; template<class...> using void_t = void; // logical operator traits template<class... B> struct conjunction; template<class... B> struct disjunction; template<class B> struct negation; // primary type categories template<class T> inline constexpr bool is_void_v = is_void<T>::value; template<class T> inline constexpr bool is_null_pointer_v = is_null_pointer<T>::value; template<class T> inline constexpr bool is_integral_v = is_integral<T>::value; template<class T> inline constexpr bool is_floating_point_v = is_floating_point<T>::value; template<class T> inline constexpr bool is_array_v = is_array<T>::value; template<class T> inline constexpr bool is_pointer_v = is_pointer<T>::value; template<class T> inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<T>::value; template<class T> inline constexpr bool is_rvalue_reference_v = is_rvalue_reference<T>::value; template<class T> inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<T>::value; template<class T> inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<T>::value; template<class T> inline constexpr bool is_enum_v = is_enum<T>::value; template<class T> inline constexpr bool is_union_v = is_union<T>::value; template<class T> inline constexpr bool is_class_v = is_class<T>::value; template<class T> inline constexpr bool is_function_v = is_function<T>::value; // composite type categories template<class T> inline constexpr bool is_reference_v = is_reference<T>::value; template<class T> inline constexpr bool is_arithmetic_v = is_arithmetic<T>::value; template<class T> inline constexpr bool is_fundamental_v = is_fundamental<T>::value; template<class T> inline constexpr bool is_object_v = is_object<T>::value; template<class T> inline constexpr bool is_scalar_v = is_scalar<T>::value; template<class T> inline constexpr bool is_compound_v = is_compound<T>::value; template<class T> inline constexpr bool is_member_pointer_v = is_member_pointer<T>::value; // type properties template<class T> inline constexpr bool is_const_v = is_const<T>::value; template<class T> inline constexpr bool is_volatile_v = is_volatile<T>::value; template<class T> inline constexpr bool is_trivial_v = is_trivial<T>::value; template<class T> inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::value; template<class T> inline constexpr bool is_standard_layout_v = is_standard_layout<T>::value; template<class T> inline constexpr bool is_empty_v = is_empty<T>::value; template<class T> inline constexpr bool is_polymorphic_v = is_polymorphic<T>::value; template<class T> inline constexpr bool is_abstract_v = is_abstract<T>::value; template<class T> inline constexpr bool is_final_v = is_final<T>::value; template<class T> inline constexpr bool is_aggregate_v = is_aggregate<T>::value; template<class T> inline constexpr bool is_signed_v = is_signed<T>::value; template<class T> inline constexpr bool is_unsigned_v = is_unsigned<T>::value; template<class T> inline constexpr bool is_bounded_array_v = is_bounded_array<T>::value; template<class T> inline constexpr bool is_unbounded_array_v = is_unbounded_array<T>::value; template<class T> inline constexpr bool is_scoped_enum_v = is_scoped_enum<T>::value; template<class T, class... Args> inline constexpr bool is_constructible_v = is_constructible<T, Args...>::value; template<class T> inline constexpr bool is_default_constructible_v = is_default_constructible<T>::value; template<class T> inline constexpr bool is_copy_constructible_v = is_copy_constructible<T>::value; template<class T> inline constexpr bool is_move_constructible_v = is_move_constructible<T>::value; template<class T, class U> inline constexpr bool is_assignable_v = is_assignable<T, U>::value; template<class T> inline constexpr bool is_copy_assignable_v = is_copy_assignable<T>::value; template<class T> inline constexpr bool is_move_assignable_v = is_move_assignable<T>::value; template<class T, class U> inline constexpr bool is_swappable_with_v = is_swappable_with<T, U>::value; template<class T> inline constexpr bool is_swappable_v = is_swappable<T>::value; template<class T> inline constexpr bool is_destructible_v = is_destructible<T>::value; template<class T, class... Args> inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<T, Args...>::value; template<class T> inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<T>::value; template<class T> inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<T>::value; template<class T> inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<T>::value; template<class T, class U> inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<T, U>::value; template<class T> inline constexpr bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<T>::value; template<class T> inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<T>::value; template<class T> inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<T>::value; template<class T, class... Args> inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<T, Args...>::value; template<class T> inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<T>::value; template<class T> inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<T>::value; template<class T> inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<T>::value; template<class T, class U> inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<T, U>::value; template<class T> inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<T>::value; template<class T> inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<T>::value; template<class T, class U> inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<T, U>::value; template<class T> inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<T>::value; template<class T> inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<T>::value; template<class T> inline constexpr bool has_virtual_destructor_v = has_virtual_destructor<T>::value; template<class T> inline constexpr bool has_unique_object_representations_v = has_unique_object_representations<T>::value; template<class T, class U> inline constexpr bool reference_constructs_from_temporary_v = reference_constructs_from_temporary<T, U>::value; template<class T, class U> inline constexpr bool reference_converts_from_temporary_v = reference_converts_from_temporary<T, U>::value; // type property queries template<class T> inline constexpr size_t alignment_of_v = alignment_of<T>::value; template<class T> inline constexpr size_t rank_v = rank<T>::value; template<class T, unsigned I = 0> inline constexpr size_t extent_v = extent<T, I>::value; // type relations template<class T, class U> inline constexpr bool is_same_v = is_same<T, U>::value; template<class Base, class Derived> inline constexpr bool is_base_of_v = is_base_of<Base, Derived>::value; template<class Base, class Derived> inline constexpr bool is_virtual_base_of_v = is_virtual_base_of<Base, Derived>::value; template<class From, class To> inline constexpr bool is_convertible_v = is_convertible<From, To>::value; template<class From, class To> inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<From, To>::value; template<class T, class U> inline constexpr bool is_layout_compatible_v = is_layout_compatible<T, U>::value; template<class Base, class Derived> inline constexpr bool is_pointer_interconvertible_base_of_v = is_pointer_interconvertible_base_of<Base, Derived>::value; template<class Fn, class... ArgTypes> inline constexpr bool is_invocable_v = is_invocable<Fn, ArgTypes...>::value; template<class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v = is_invocable_r<R, Fn, ArgTypes...>::value; template<class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<Fn, ArgTypes...>::value; template<class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value; // logical operator traits template<class... B> inline constexpr bool conjunction_v = conjunction<B...>::value; template<class... B> inline constexpr bool disjunction_v = disjunction<B...>::value; template<class B> inline constexpr bool negation_v = negation<B>::value; // member relationships template<class S, class M> constexpr bool is_pointer_interconvertible_with_class(M S::*m) noexcept; template<class S1, class S2, class M1, class M2> constexpr bool is_corresponding_member(M1 S1::*m1, M2 S2::*m2) noexcept; // constant evaluation context constexpr bool is_constant_evaluated() noexcept; consteval bool is_within_lifetime(const auto*) noexcept; }
[編輯] 類模板 std::integral_constant
namespace std { template <class T, T v> struct integral_constant { static constexpr T value = v; using value_type = T; using type = integral_constant<T, v>; constexpr operator value_type() const noexcept { return value; } constexpr value_type operator()() const noexcept { return value; } }; }