Spec-Zone.ru › C++

Заголовок стандартной библиотеки <utility>

Этот заголовок является частью библиотеки общих утилит.

Подключаемые заголовки

<compare>
(C++20)
поддержка оператора трёхстороннего сравнения
<initializer_list>
(C++11)
шаблон класса std::initializer_list

Пространства имён

rel_ops Предоставляет операторы сравнения автоматически
Определено в пространстве имён std::rel_ops
operator!=operator>operator<=operator>=
(устарело в C++20)
автоматически генерирует операторы сравнения на основе определённых пользователем operator== и operator<
(шаблон функции)

Функции

swap
меняет местами значения двух объектов
(шаблон функции)
exchange
(C++14)
заменяет аргумент новым значением и возвращает его предыдущее значение
(шаблон функции)
forward
(C++11)
передаёт аргумент функции, используя аргумент шаблона типа для сохранения категории значения
(шаблон функции)
forward_like
(C++23)
передаёт аргумент функции так, как если бы он был приведён к категории значения и константности выражения указанного аргумента шаблона типа
(шаблон функции)
move
(C++11)
преобразует аргумент в xvalue
(шаблон функции)
move_if_noexcept
(C++11)
преобразует аргумент в xvalue, если конструктор перемещения не выбрасывает исключений
(шаблон функции)
as_const
(C++17)
получает ссылку на const для своего аргумента
(шаблон функции)
declval
(C++11)
получает ссылку на объект типа, заданного аргументом шаблона, для использования в невычисляемом контексте
(шаблон функции)
to_underlying
(C++23)
преобразует перечисление в его базовый тип
(шаблон функции)
cmp_equalcmp_not_equalcmp_lesscmp_greatercmp_less_equalcmp_greater_equal
(C++20)
сравнивает два целочисленных значения, гарантируя, что отрицательные числа со знаком меньше беззнаковых чисел
(шаблон функции)
in_range
(C++20)
проверяет, входит ли целочисленное значение в диапазон заданного целочисленного типа
(шаблон функции)
unreachable
(C++23)
помечает недостижимую точку выполнения
(функция)
make_pair
создаёт объект pair типа, определяемого типами аргументов
(шаблон функции)
operator==operator!=operator<operator<=operator>operator>=operator<=>
(удалён в C++20)(удалён в C++20)(удалён в C++20)(удалён в C++20)(удалён в C++20)(C++20)
лексикографически сравнивает значения в pair
(шаблон функции)
std::swap(std::pair)
(C++11)
специализирует алгоритм std::swap
(шаблон функции)
get(std::pair)
(C++11)
обращается к элементу pair
(шаблон функции)

Классы

pair
реализует бинарный кортеж, то есть пару значений
(шаблон класса)
tuple_size
(C++11)
получает количество элементов типа, подобного кортежу
(шаблон класса)
tuple_element
(C++11)
получает типы элементов типа, подобного кортежу
(шаблон класса)
std::tuple_size<std::pair>
(C++11)
получает размер pair
(специализация шаблона класса)
std::tuple_element<std::pair>
(C++11)
получает тип элементов pair
(специализация шаблона класса)
integer_sequence
(C++14)
реализует последовательность целых чисел времени компиляции
(шаблон класса)
Предварительные объявления
Определено в заголовке <tuple>
tuple
(C++11)
реализует контейнер фиксированного размера, содержащий элементы, типы которых могут различаться
(шаблон класса)
Определено в заголовке <variant>
monostate
(C++17)
тип-заполнитель, используемый в качестве первой альтернативы в variant из типов, не имеющих конструктора по умолчанию
(класс)

Константы

ignore
(C++11)
заполнитель для пропуска элемента при распаковке tuple с помощью tie
(константа)

Теги

piecewise_constructpiecewise_construct_t
(C++11)
тег поэлементного конструирования
(тег)
in_placein_place_typein_place_indexin_place_tin_place_type_tin_place_index_t
(C++17)
тег конструирования на месте
(тег)
nontype nontype_t
(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>;
}

См. также

<tuple>
(C++11)
шаблон класса std::tuple

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/header/utility

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API