22 General utilities library [utilities] (original) (raw)
The header contains some basic function and class templates that are used throughout the rest of the library.
#include <compare> #include <initializer_list> namespace std { template<class T> constexpr 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<T>);template<class T, class U = T> constexpr T exchange(T& obj, U&& new_val) noexcept(see below);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 auto forward_like(U&& x) noexcept -> see below;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;template<class T> constexpr add_const_t<T>& as_const(T& t) noexcept;template<class T> void as_const(const T&&) = delete;template<class T> add_rvalue_reference_t<T> declval() noexcept; 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;template<class T> constexpr underlying_type_t<T> to_underlying(T value) noexcept;[[noreturn]] void unreachable();void observable_checkpoint() noexcept;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 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)>;template<class T> struct tuple_size;template<size_t I, class T> struct tuple_element;template<class T, T... Values> struct tuple_size<integer_sequence<T, Values...>>;template<size_t I, class T, T... Values> struct tuple_element<I, integer_sequence<T, Values...>>;template<size_t I, class T, T... Values> struct tuple_element<I, const integer_sequence<T, Values...>>;template<size_t I, class T, T... Values> constexpr T get(integer_sequence<T, Values...>) noexcept;template<class T1, class T2> struct pair;template<class T1, class T2, class U1, class U2,template<class> class TQual, template<class> class UQual> requires requires { typename pair<common_reference_t<TQual<T1>, UQual<U1>>, common_reference_t<TQual<T2>, UQual<U2>>>; } struct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual> { using type = pair<common_reference_t<TQual<T1>, UQual<U1>>, common_reference_t<TQual<T2>, UQual<U2>>>;};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>>;};template<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&&);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;struct piecewise_construct_t { explicit piecewise_construct_t() = default;};inline constexpr piecewise_construct_t piecewise_construct{};template<class... Types> class tuple; 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> 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> constexpr in_place_index_t<I> in_place_index{};template<auto V> struct constant_arg_t { explicit constant_arg_t() = default;};template<auto V> constexpr constant_arg_t<V> constant_arg{};struct monostate;constexpr bool operator==(monostate, monostate) noexcept;constexpr strong_ordering operator<=>(monostate, monostate) noexcept;template<class T> struct hash;template<> struct hash<monostate>;}
Constraints: is_move_constructible_v<T> is true andis_move_assignable_v<T> is true.
Effects: Exchanges values stored in two locations.
Remarks: The exception specification is equivalent to:is_nothrow_move_constructible_v<T> && is_nothrow_move_assignable_v<T>
Constraints: is_swappable_v<T> is true.
Effects: As if by swap_ranges(a, a + N, b).
Effects: Equivalent to:T old_val = std::move(obj); obj = std::forward<U>(new_val);return old_val;
Remarks: The exception specification is equivalent to:is_nothrow_move_constructible_v<T> && is_nothrow_assignable_v<T&, U>
The library provides templated helper functions to simplify applying move semantics to an lvalue and to simplify the implementation of forwarding functions.
All functions specified in this subclause are signal-safe.
Mandates: For the second overload, is_lvalue_reference_v<T> is false.
Returns: static_cast<T&&>(t).
Returns: static_cast<V>(x).
Remarks: The return type is V.
Returns: static_cast<remove_reference_t<T>&&>(t).
The library provides the function template declval to simplify the definition of expressions which occur as unevaluated operands.
Remarks: The template parameter T of declval may be an incomplete type.
Effects: Equivalent to:using UT = make_unsigned_t<T>;using UU = make_unsigned_t<U>;if constexpr (is_signed_v<T> == is_signed_v<U>) return t == u;else if constexpr (is_signed_v<T>) return t < 0 ? false : UT(t) == u;else return u < 0 ? false : t == UU(u);
Effects: Equivalent to: return !cmp_equal(t, u);
Effects: Equivalent to:using UT = make_unsigned_t<T>;using UU = make_unsigned_t<U>;if constexpr (is_signed_v<T> == is_signed_v<U>) return t < u;else if constexpr (is_signed_v<T>) return t < 0 ? true : UT(t) < u;else return u < 0 ? false : t < UU(u);
Effects: Equivalent to: return cmp_less(u, t);
Effects: Equivalent to: return !cmp_greater(t, u);
Effects: Equivalent to: return !cmp_less(t, u);
Effects: Equivalent to:return cmp_greater_equal(t, numeric_limits<R>::min()) && cmp_less_equal(t, numeric_limits<R>::max());
Returns: static_cast<underlying_type_t<T>>(value).
Preconditions: false is true.
[Note 1:
This precondition cannot be satisfied, thus the behavior of calling unreachable is undefined.
— _end note_]