Files
cppdraft_translate/cppdraft/utility/syn.md
2025-10-25 03:02:53 +03:00

7.8 KiB

[utility.syn]

22 General utilities library [utilities]

22.2 Utility components [utility]

22.2.1 Header synopsis [utility.syn]

1

#

The header contains some basic function and class templates that are used throughout the rest of the library.

// all freestanding#include // see [compare.syn]#include <initializer_list> // see [initializer.list.syn]namespace std {// [utility.swap], swaptemplateconstexpr void swap(T& a, T& b) noexcept(see below); template<class T, size_t N>constexpr void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v); // [utility.exchange], exchangetemplate<class T, class U = T>constexpr T exchange(T& obj, U&& new_val) noexcept(see below); // [forward], forward/movetemplateconstexpr T&& forward(remove_reference_t& t) noexcept; templateconstexpr T&& forward(remove_reference_t&& t) noexcept; template<class T, class U>constexpr auto forward_like(U&& x) noexcept -> see below; templateconstexpr remove_reference_t&& move(T&&) noexcept; templateconstexpr conditional_t<!is_nothrow_move_constructible_v && is_copy_constructible_v, const T&, T&&> move_if_noexcept(T& x) noexcept; // [utility.as.const], as_consttemplateconstexpr add_const_t& as_const(T& t) noexcept; templatevoid as_const(const T&&) = delete; // [declval], declvaltemplate add_rvalue_reference_t declval() noexcept; // as unevaluated operand// [utility.intcmp], integer comparison functionstemplate<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; // [utility.underlying], to_underlyingtemplateconstexpr underlying_type_t to_underlying(T value) noexcept; // [utility.undefined], undefined behaviornoreturn void unreachable(); void observable_checkpoint() noexcept; // [intseq], compile-time integer sequencestemplate<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 below>; 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)>; // [pairs], class template pairtemplate<class T1, class T2>struct pair; template<class T1, class T2, class U1, class U2, template class TQual, template class UQual>requires requires { typename pair<common_reference_t<TQual, UQual>, common_reference_t<TQual, UQual>>; }struct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual> {using type = pair<common_reference_t<TQual, UQual>, common_reference_t<TQual, UQual>>; }; template<class T1, class T2, class U1, class U2>requires requires { typename pair<common_type_t<T1, U1>, common_type_t<T2, U2>>; }struct common_type<pair<T1, T2>, pair<U1, U2>> {using type = pair<common_type_t<T1, U1>, common_type_t<T2, U2>>; }; // [pairs.spec], pair specialized algorithmstemplate<class T1, class T2, class U1, class U2>constexpr bool operator==(const pair<T1, T2>&, const pair<U1, U2>&); template<class T1, class T2, class U1, class U2>constexpr common_comparison_category_t<synth-three-way-result<T1, U1>, synth-three-way-result<T2, U2>>operator<=>(const pair<T1, T2>&, const pair<U1, U2>&); 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 void swap(const pair<T1, T2>& x, const pair<T1, T2>& y)noexcept(noexcept(x.swap(y))); template<class T1, class T2>constexpr see below make_pair(T1&&, T2&&); // [pair.astuple], tuple-like access to pairtemplate 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], pair piecewise constructionstruct piecewise_construct_t {explicit piecewise_construct_t() = default; }; inline constexpr piecewise_construct_t piecewise_construct{}; template<class... Types> class tuple; // defined in // in-place constructionstruct in_place_t {explicit in_place_t() = default; }; inline constexpr in_place_t in_place{}; templatestruct in_place_type_t {explicit in_place_type_t() = default; }; template constexpr in_place_type_t in_place_type{}; template<size_t I>struct in_place_index_t {explicit in_place_index_t() = default; }; template<size_t I> constexpr in_place_index_t in_place_index{}; // nontype argument tagtemplatestruct nontype_t {explicit nontype_t() = default; }; template constexpr nontype_t nontype{}; // [variant.monostate], class monostatestruct monostate; // [variant.monostate.relops], monostate relational operatorsconstexpr bool operator==(monostate, monostate) noexcept; constexpr strong_ordering operator<=>(monostate, monostate) noexcept; // [variant.hash], hash supporttemplate struct hash; template<> struct hash;}