Standard library header <concepts> (C++20)
From cppreference.net
Этот заголовок является частью библиотеки concepts .
Концепции |
|
Основные концепции языка |
|
|
(C++20)
|
указывает, что тип идентичен другому типу
(концепт) |
|
(C++20)
|
указывает, что тип является производным от другого типа
(concept) |
|
(C++20)
|
определяет, что тип неявно преобразуется в другой тип
(concept) |
|
(C++20)
|
указывает, что два типа имеют общий ссылочный тип
(concept) |
|
(C++20)
|
указывает, что два типа имеют общий тип
(concept) |
|
(C++20)
|
определяет, что тип является целочисленным типом
(концепт) |
|
(C++20)
|
указывает, что тип является целочисленным типом со знаком
(концепт) |
|
(C++20)
|
указывает, что тип является целочисленным типом без знака
(концепт) |
|
(C++20)
|
определяет, что тип является типом с плавающей запятой
(концепт) |
|
(C++20)
|
определяет, что тип может быть присвоен из другого типа
(concept) |
|
(C++20)
|
определяет, что тип может быть обменян или что два типа могут быть обменены друг с другом
(концепт) |
|
(C++20)
|
определяет, что объект данного типа может быть уничтожен
(концепт) |
|
(C++20)
|
определяет, что переменная данного типа может быть сконструирована из или связана с набором типов аргументов
(концепт) |
|
(C++20)
|
указывает, что объект типа может быть сконструирован по умолчанию
(концепт) |
|
(C++20)
|
определяет, что объект типа может быть перемещён при конструировании
(концепт) |
|
(C++20)
|
определяет, что объект типа может быть скопирован и перемещен конструктором
(concept) |
Концепции сравнения |
|
|
определяет, что оператор
==
является отношением эквивалентности
(концепт) |
|
|
определяет, что операторы сравнения для типа задают отношение полного порядка
(концепт) |
|
Концепции объектов |
|
|
(C++20)
|
определяет, что объект типа может быть перемещён и обменян
(концепт) |
|
(C++20)
|
определяет, что объект типа может быть скопирован, перемещён и обменян
(концепт) |
|
(C++20)
|
определяет, что объект типа может быть скопирован, перемещён, обменян и создан по умолчанию
(концепт) |
|
(C++20)
|
указывает, что тип является регулярным, то есть одновременно
semiregular
и
equality_comparable
(концепт) |
Концепции вызываемых объектов |
|
|
(C++20)
|
определяет, что вызываемый тип может быть вызван с заданным набором типов аргументов
(concept) |
|
(C++20)
|
определяет, что вызываемый тип является булевым предикатом
(концепт) |
|
(C++20)
|
определяет, что вызываемый тип является бинарным отношением
(concept) |
|
(C++20)
|
определяет, что
relation
задаёт отношение эквивалентности
(концепт) |
|
(C++20)
|
определяет, что
relation
задает строгое слабое упорядочение
(концепт) |
Объекты точек кастомизации |
|
|
(C++20)
|
обменивает значения двух объектов
(объект точки кастомизации) |
Синопсис
// все независимые namespace std { // концепции, связанные с языком // концепция same_as template<class T, class U> concept same_as = /* см. описание */; // концепция derived_from template<class Derived, class Base> concept derived_from = /* см. описание */; // концепция convertible_to template<class From, class To> concept convertible_to = /* см. описание */; // концепция common_reference_with template<class T, class U> concept common_reference_with = /* см. описание */; // концепция common_with template<class T, class U> concept common_with = /* см. описание */; // арифметические концепции template<class T> concept integral = /* см. описание */; template<class T> concept signed_integral = /* см. описание */; template<class T> concept unsigned_integral = /* см. описание */; template<class T> concept floating_point = /* см. описание */; // концепция assignable_from template<class LHS, class RHS> concept assignable_from = /* см. описание */; // концепция swappable namespace ranges { inline namespace /* не указано */ { inline constexpr /* не указано */ swap = /* не указано */; } } template<class T> concept swappable = /* см. описание */; template<class T, class U> concept swappable_with = /* см. описание */; // концепция destructible template<class T> concept destructible = /* см. описание */; // концепция constructible_from template<class T, class... Args> concept constructible_from = /* см. описание */; // концепция default_initializable template<class T> concept default_initializable = /* см. описание */; // концепция move_constructible template<class T> concept move_constructible = /* см. описание */; // концепция copy_constructible template<class T> concept copy_constructible = /* см. описание */; // концепции сравнения // концепция equality_comparable template<class T> concept equality_comparable = /* см. описание */; template<class T, class U> concept equality_comparable_with = /* см. описание */; // концепция totally_ordered template<class T> concept totally_ordered = /* см. описание */; template<class T, class U> concept totally_ordered_with = /* см. описание */; // объектные концепции template<class T> concept movable = /* см. описание */; template<class T> concept copyable = /* см. описание */; template<class T> concept semiregular = /* см. описание */; template<class T> concept regular = /* см. описание */; // вызываемые концепции // концепция invocable template<class F, class... Args> concept invocable = /* см. описание */; // концепция regular_invocable template<class F, class... Args> concept regular_invocable = /* см. описание */; // концепция predicate template<class F, class... Args> concept predicate = /* см. описание */; // концепция relation template<class R, class T, class U> concept relation = /* см. описание */; // концепция equivalence_relation template<class R, class T, class U> concept equivalence_relation = /* см. описание */; // концепция strict_weak_order template<class R, class T, class U> concept strict_weak_order = /* см. описание */; }
Вспомогательная концепция
boolean-testable
template<class T> concept /*boolean-testable-impl*/ = convertible_to<T, bool>; // только для экспозиции; template<class T> concept boolean-testable = // только для экспозиции /*boolean-testable-impl*/<T> && requires(T&& t) { { !std::forward<T>(t) } -> /*boolean-testable-impl*/; };
Концепт
same_as
template<class T, class U> concept /*same-as-impl*/ = is_same_v<T, U>; // только для экспозиции template<class T, class U> concept same_as = /*same-as-impl*/<T, U> && /*same-as-impl*/<U, T>;
Концепт
derived_from
template<class Derived, class Base> concept derived_from = is_base_of_v<Base, Derived> && is_convertible_v<const volatile Derived*, const volatile Base*>;
Концепт
convertible_to
template<class From, class To> concept convertible_to = is_convertible_v<From, To> && requires { static_cast<To>(declval<From>()); };
Концепт
common_reference_with
template<class T, class U> concept common_reference_with = same_as<common_reference_t<T, U>, common_reference_t<U, T>> && convertible_to<T, common_reference_t<T, U>> && convertible_to<U, common_reference_t<T, U>>;
Концепт
common_with
template<class T, class U> concept common_with = same_as<common_type_t<T, U>, common_type_t<U, T>> && requires { static_cast<common_type_t<T, U>>(declval<T>()); static_cast<common_type_t<T, U>>(declval<U>()); } && common_reference_with<add_lvalue_reference_t<const T>, add_lvalue_reference_t<const U>> && common_reference_with< add_lvalue_reference_t<common_type_t<T, U>>, common_reference_t<add_lvalue_reference_t<const T>, add_lvalue_reference_t<const U>>>;
Концепт
integral
template<class T> concept integral = is_integral_v<T>;
Концепт
signed_integral
template<class T> concept signed_integral = integral<T> && is_signed_v<T>;
Концепт
unsigned_integral
template<class T> concept unsigned_integral = integral<T> && !signed_integral<T>;
Концепт
floating_point
template<class T> concept floating_point = is_floating_point_v<T>;
Концепт
assignable_from
template<class LHS, class RHS> concept assignable_from = is_lvalue_reference_v<LHS> && common_reference_with<const remove_reference_t<LHS>&, const remove_reference_t<RHS>&> && requires(LHS lhs, RHS&& rhs) { { lhs = std::forward<RHS>(rhs) } -> same_as<LHS>; };
Концепт
swappable
template<class T> concept swappable = requires(T& a, T& b) { ranges::swap(a, b); };
Концепт
swappable_with
template<class T, class U> concept swappable_with = common_reference_with<T, U> && requires(T&& t, U&& u) { ranges::swap(std::forward<T>(t), std::forward<T>(t)); ranges::swap(std::forward<U>(u), std::forward<U>(u)); ranges::swap(std::forward<T>(t), std::forward<U>(u)); ranges::swap(std::forward<U>(u), std::forward<T>(t)); };
Концепт
destructible
template<class T> concept destructible = is_nothrow_destructible_v<T>;
Концепт
constructible_from
template<class T, class... Args> concept constructible_from = destructible<T> && is_constructible_v<T, Args...>;
Концепт
default_initializable
template<class T> constexpr bool /*is-default-initializable*/ = /* см. описание */; // только для демонстрации template<class T> concept default_initializable = constructible_from<T> && requires { T{}; } && /*is-default-initializable*/<T>;
Концепт
move_constructible
template<class T> concept move_constructible = constructible_from<T, T> && convertible_to<T, T>;
Концепт
copy_constructible
template<class T> concept copy_constructible = move_constructible<T> && constructible_from<T, T&> && convertible_to<T&, T> && constructible_from<T, const T&> && convertible_to<const T&, T> && constructible_from<T, const T> && convertible_to<const T, T>;
Концепт
equality_comparable
template<class T, class U> concept /*weakly-equality-comparable-with*/ = // только для пояснения requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) { { t == u } -> boolean-testable; { t != u } -> boolean-testable; { u == t } -> boolean-testable; { u != t } -> boolean-testable; }; template<class T> concept equality_comparable = /*weakly-equality-comparable-with*/<T, T>;
Концепт
equality_comparable_with
template<class T, class U, class C = common_reference_t<const T&, const U&>> concept /*comparison-common-type-with-impl*/ = // только для экспозиции same_as<common_reference_t<const T&, const U&>, common_reference_t<const U&, const T&>> && requires { requires convertible_to<const T&, const C&> || convertible_to<T, const C&>; requires convertible_to<const U&, const C&> || convertible_to<U, const C&>; }; template<class T, class U> concept /*comparison-common-type-with*/ = // только для экспозиции /*comparison-common-type-with-impl*/<remove_cvref_t<T>, remove_cvref_t<U>>; template<class T, class U> concept equality_comparable_with = equality_comparable<T> && equality_comparable<U> && /*comparison-common-type-with*/<T, U> && equality_comparable< common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>> && /*weakly-equality-comparable-with*/<T, U>;
Вспомогательное понятие partially-ordered-with
Определено в заголовке <compare>
template<class T, class U> concept /*частично-упорядочено-с*/ = // только для демонстрации requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) { { t < u } -> boolean-testable; { t > u } -> boolean-testable; { t <= u } -> boolean-testable; { t >= u } -> boolean-testable; { u < t } -> boolean-testable; { u > t } -> boolean-testable; { u <= t } -> boolean-testable; { u >= t } -> boolean-testable; };
Концепт
totally_ordered
template<class T> concept totally_ordered = equality_comparable<T> && /*частично-упорядочен-с*/<T, T>;
Концепт
totally_ordered_with
template<class T, class U> concept totally_ordered_with = totally_ordered<T> && totally_ordered<U> && equality_comparable_with<T, U> && totally_ordered< common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>> && /*частично-упорядочен-с*/<T, U>;
Концепт
movable
template<class T> concept movable = is_object_v<T> && move_constructible<T> && assignable_from<T&, T> && swappable<T>;
Концепт
copyable
template<class T> concept copyable = copy_constructible<T> && movable<T> && assignable_from<T&, T&> && assignable_from<T&, const T&> && assignable_from<T&, const T>;
Концепт
semiregular
template<class T> concept semiregular = copyable<T> && default_initializable<T>;
Концепт
regular
template<class T> concept regular = semiregular<T> && equality_comparable<T>;
Концепт
invocable
template<class F, class... Args> concept invocable = requires(F&& f, Args&&... args) { invoke(std::forward<F>(f), std::forward<Args>(args)...); // не требуется сохранять равенство };
Концепт
regular_invocable
template<class F, class... Args> concept regular_invocable = invocable<F, Args...>;
Концепт
predicate
template<class F, class... Args> concept predicate = regular_invocable<F, Args...> && boolean-testable<invoke_result_t<F, Args...>>;
Концепт
relation
template<class R, class T, class U> concept relation = predicate<R, T, T> && predicate<R, U, U> && predicate<R, T, U> && predicate<R, U, T>;
Концепт
equivalence_relation
template<class R, class T, class U> concept отношение_эквивалентности = relation<R, T, U>;
Концепт
strict_weak_order
template<class R, class T, class U> concept strict_weak_order = relation<R, T, U>;