標準庫標頭檔案 <utility>
來自 cppreference.com
此標頭檔案是通用工具庫的一部分。
包含 | ||
(C++20) |
三向比較運算子支援 | |
(C++11) |
std::initializer_list 類模板 | |
名稱空間 | ||
rel_ops
|
提供自動比較運算子 | |
定義於名稱空間
std::rel_ops | ||
(C++20 中已棄用) |
基於使用者定義的 operator== 和 operator< 自動生成比較運算子 (函式模板) | |
函式 | ||
交換兩個物件的值 (函式模板) | ||
(C++14) |
用新值替換引數並返回其舊值 (函式模板) | |
(C++11) |
轉發函式引數並使用型別模板引數來保留其值類別 (函式模板) | |
(C++23) |
轉發函式引數,如同將其轉換為指定型別模板引數表示式的值類別和常量性 (函式模板) | |
(C++11) |
將引數轉換為亡值 (函式模板) | |
(C++11) |
如果移動建構函式不丟擲異常,則將引數轉換為亡值 (函式模板) | |
(C++17) |
獲取其引數的 const 引用 (函式模板) | |
(C++11) |
獲取模板型別引數物件的引用,用於未求值上下文 (函式模板) | |
(C++23) |
將列舉轉換為其底層型別 (函式模板) | |
比較兩個整數值,確保有符號負數小於無符號數 (函式模板) | ||
(C++20) |
檢查整數值是否在給定整數型別的範圍內 (函式模板) | |
(C++23) |
標記不可達的執行點 (函式) | |
建立型別由引數型別確定的 pair 物件(函式模板) | ||
(C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20) |
字典序比較 pair 中的值(函式模板) | |
(C++11) |
特化 std::swap 演算法 (函式模板) | |
(C++11) |
訪問 pair 的元素(函式模板) | |
類 | ||
實現二元組,即一對值 (類模板) | ||
(C++11) |
獲取類元組型別元素的數量 (類模板) | |
(C++11) |
獲取類元組型別的元素型別 (類模板) | |
(C++11) |
獲取 pair 的大小(類模板特化) | |
獲取 pair 元素的型別(類模板特化) | ||
(C++14) |
實現編譯時整數序列 (類模板) | |
前向宣告 | ||
定義於標頭檔案
<tuple> | ||
(C++11) |
實現固定大小容器,容納可能不同型別的元素 (類模板) | |
定義於標頭檔案
<variant> | ||
(C++17) |
用作非預設可構造型別變體的第一個替代項的佔位符型別 (類) | |
常量 | ||
(C++11) |
使用 tie 解包 tuple 時跳過元素的佔位符(常量) | |
標籤 | ||
分段構造標籤 (標籤) | ||
原地構造標籤 (標籤) | ||
(C++26) |
值構造標籤 (標籤) |
[編輯] 概要
#include <compare> #include <initializer_list> namespace std { // swap template<class T> constexpr void swap(T& a, T& b) noexcept(/* see description */); template<class T, size_t N> constexpr void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v<T>); // exchange template<class T, class U = T> constexpr T exchange(T& obj, U&& new_val); // forward/move template<class T> constexpr T&& forward(remove_reference_t<T>& t) noexcept; template<class T> constexpr T&& forward(remove_reference_t<T>&& t) noexcept; template<class T, class U> constexpr /* see description */ forward_like(U&& x) noexcept; template<class T> constexpr remove_reference_t<T>&& move(T&&) noexcept; template<class T> constexpr conditional_t< !is_nothrow_move_constructible_v<T> && is_copy_constructible_v<T>, const T&, T&&> move_if_noexcept(T& x) noexcept; // as_const template<class T> constexpr add_const_t<T>& as_const(T& t) noexcept; template<class T> void as_const(const T&&) = delete; // declval template<class T> add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand // integer comparison functions template<class T, class U> constexpr bool cmp_equal(T t, U u) noexcept; template<class T, class U> constexpr bool cmp_not_equal(T t, U u) noexcept; template<class T, class U> constexpr bool cmp_less(T t, U u) noexcept; template<class T, class U> constexpr bool cmp_greater(T t, U u) noexcept; template<class T, class U> constexpr bool cmp_less_equal(T t, U u) noexcept; template<class T, class U> constexpr bool cmp_greater_equal(T t, U u) noexcept; template<class R, class T> constexpr bool in_range(T t) noexcept; // to_underlying template<class T> constexpr underlying_type_t<T> to_underlying(T value) noexcept; // unreachable [[noreturn]] void unreachable(); // compile-time integer sequences template<class T, T...> struct integer_sequence; template<size_t... I> using index_sequence = integer_sequence<size_t, I...>; template<class T, T N> using make_integer_sequence = integer_sequence<T, /* see description */>; template<size_t N> using make_index_sequence = make_integer_sequence<size_t, N>; template<class... T> using index_sequence_for = make_index_sequence<sizeof...(T)>; // class template pair template<class T1, class T2> struct pair; // pair specialized algorithms template<class T1, class T2> constexpr bool operator==(const pair<T1, T2>&, const pair<T1, T2>&); template<class T1, class T2> constexpr common_comparison_category_t</*synth-three-way-result*/<T1>, /*synth-three-way-result*/<T2>> operator<=>(const pair<T1, T2>&, const pair<T1, T2>&); template<class T1, class T2> constexpr void swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); template<class T1, class T2> constexpr /* see description */ make_pair(T1&&, T2&&); // tuple-like access to pair template<class T> struct tuple_size; template<size_t I, class T> struct tuple_element; template<class T1, class T2> struct tuple_size<pair<T1, T2>>; template<size_t I, class T1, class T2> struct tuple_element<I, pair<T1, T2>>; template<size_t I, class T1, class T2> constexpr tuple_element_t<I, pair<T1, T2>>& get(pair<T1, T2>&) noexcept; template<size_t I, class T1, class T2> constexpr tuple_element_t<I, pair<T1, T2>>&& get(pair<T1, T2>&&) noexcept; template<size_t I, class T1, class T2> constexpr const tuple_element_t<I, pair<T1, T2>>& get(const pair<T1, T2>&) noexcept; template<size_t I, class T1, class T2> constexpr const tuple_element_t<I, pair<T1, T2>>&& get(const pair<T1, T2>&&) noexcept; template<class T1, class T2> constexpr T1& get(pair<T1, T2>& p) noexcept; template<class T1, class T2> constexpr const T1& get(const pair<T1, T2>& p) noexcept; template<class T1, class T2> constexpr T1&& get(pair<T1, T2>&& p) noexcept; template<class T1, class T2> constexpr const T1&& get(const pair<T1, T2>&& p) noexcept; template<class T2, class T1> constexpr T2& get(pair<T1, T2>& p) noexcept; template<class T2, class T1> constexpr const T2& get(const pair<T1, T2>& p) noexcept; template<class T2, class T1> constexpr T2&& get(pair<T1, T2>&& p) noexcept; template<class T2, class T1> constexpr const T2&& get(const pair<T1, T2>&& p) noexcept; // pair piecewise construction struct piecewise_construct_t { explicit piecewise_construct_t() = default; }; inline constexpr piecewise_construct_t piecewise_construct{}; template<class... Types> class tuple; // defined in <tuple> // in-place construction struct in_place_t { explicit in_place_t() = default; }; inline constexpr in_place_t in_place{}; template<class T> struct in_place_type_t { explicit in_place_type_t() = default; }; template<class T> inline constexpr in_place_type_t<T> in_place_type{}; template<size_t I> struct in_place_index_t { explicit in_place_index_t() = default; }; template<size_t I> inline constexpr in_place_index_t<I> in_place_index{}; // nontype argument tag template<auto V> struct nontype_t { explicit nontype_t() = default; }; template<auto V> inline constexpr nontype_t<V> nontype{}; } // deprecated namespace std::rel_ops { template<class T> bool operator!=(const T&, const T&); template<class T> bool operator> (const T&, const T&); template<class T> bool operator<=(const T&, const T&); template<class T> bool operator>=(const T&, const T&); }
[編輯] 類模板 std::integer_sequence
namespace std { template<class T, T... I> struct integer_sequence { using value_type = T; static constexpr size_t size() noexcept { return sizeof...(I); } }; }
[編輯] 類模板 std::pair
namespace std { template<class T1, class T2> struct pair { using first_type = T1; using second_type = T2; T1 first; T2 second; pair(const pair&) = default; pair(pair&&) = default; constexpr explicit(/* see description */) pair(); constexpr explicit(/* see description */) pair(const T1& x, const T2& y); template<class U1 = T1, class U2 = T2> constexpr explicit(/* see description */) pair(U1&& x, U2&& y); template<class U1, class U2> constexpr explicit(/* see description */) pair(const pair<U1, U2>& p); template<class U1, class U2> constexpr explicit(/* see description */) pair(pair<U1, U2>&& p); template<class... Args1, class... Args2> constexpr pair(piecewise_construct_t, tuple<Args1...> first_args, tuple<Args2...> second_args); constexpr pair& operator=(const pair& p); template<class U1, class U2> constexpr pair& operator=(const pair<U1, U2>& p); constexpr pair& operator=(pair&& p) noexcept(/* see description */); template<class U1, class U2> constexpr pair& operator=(pair<U1, U2>&& p); constexpr void swap(pair& p) noexcept(/* see description */); }; template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>; }
[編輯] 參閱
(C++11) |
std::tuple 類模板 |