Заголовочный файл стандартной библиотеки <concepts>
Материал из cppreference.com
Этот заголовок является частью библиотеки концептов.
Концепты | |
Основные концепты языка | |
(C++20) |
указывает, что тип совпадает с другим типом (концепт) |
(C++20) |
указывает, что тип является производным от другого типа (концепт) |
(C++20) |
указывает, что тип неявно преобразуется в другой тип (концепт) |
(C++20) |
указывает, что два типа имеют общий ссылочный тип (концепт) |
(C++20) |
указывает, что два типа имеют общий тип (концепт) |
(C++20) |
указывает, что тип является целым типом (концепт) |
(C++20) |
указывает, что тип является целочисленным типом со знаком (концепт) |
(C++20) |
указывает, что тип является целым беззнаковым типом (концепт) |
(C++20) |
указывает, что тип, это число с плавающей точкой (концепт) |
(C++20) |
указывает, что типу может быть присвоен другой тип (концепт) |
(C++20) |
указывает, что тип можно обменять или что два типа можно обменять друг с другом (концепт) |
(C++20) |
указывает, что объект данного типа может быть уничтожен (концепт) |
(C++20) |
указывает, что переменная типа может быть создана из набора или привязана к типам аргументов (концепт) |
(C++20) |
указывает, что объект типа может быть сконструирован по умолчанию (концепт) |
(C++20) |
указывает, что объект типа может быть сконструирован перемещением (концепт) |
(C++20) |
указывает, что объект типа может быть создан копированием и перемещением (концепт) |
Концепты сравнения | |
указывает, что оператор == является отношением эквивалентности (концепт) | |
| указывает, что операторы сравнения для типа дают общий порядок (концепт) | |
Концепты объекта | |
(C++20) |
указывает, что объект типа можно перемещать и менять местами (концепт) |
(C++20) |
указывает, что объект типа можно копировать, перемещать и менять местами (концепт) |
(C++20) |
указывает, что объект типа можно копировать, перемещать, менять местами и создавать по умолчанию (концепт) |
(C++20) |
указывает, что тип является регулярным, то есть одновременно semiregular и equality_comparable (концепт) |
Вызываемые концепты | |
(C++20) |
указывает, что вызываемый тип может быть вызван с заданным набором типов аргументов (концепт) |
(C++20) |
указывает, что вызываемый тип является логическим предикатом (концепт) |
(C++20) |
указывает, что вызываемый тип является бинарным отношением (концепт) |
(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 = /* смотрите описаниеn */;
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 = /* смотрите описание */;
}
Концепт same_as
template<class T, class U>
concept __SameImpl = is_same_v<T, U>; // только экспозиция
template<class T, class U>
concept same_as = __SameImpl<T, U> && __SameImpl<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(From (&f)()) {
static_cast<To>(f());
};
Концепт 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<const remove_reference_t<T>&, const remove_reference_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>
inline 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 __WeaklyEqualityComparableWith = // только экспозиция
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 = __WeaklyEqualityComparableWith<T, T>;
Концепт equality_comparable_with
template<class T, class U>
concept equality_comparable_with =
equality_comparable<T> && equality_comparable<U> &&
common_reference_with<const remove_reference_t<T>&, const remove_reference_t<U>&> &&
equality_comparable<
common_reference_t<
const remove_reference_t<T>&,
const remove_reference_t<U>&>> &&
__WeaklyEqualityComparableWith<T, U>;
Концепт totally_ordered
template<class T>
concept totally_ordered =
equality_comparable<T> &&
requires(const remove_reference_t<T>& a,
const remove_reference_t<T>& b) {
{ a < b } -> boolean-testable;
{ a > b } -> boolean-testable;
{ a <= b } -> boolean-testable;
{ a >= b } -> boolean-testable;
};
Концепт totally_ordered_with
template<class T, class U>
concept totally_ordered_with =
totally_ordered<T> && totally_ordered<U> &&
common_reference_with<const remove_reference_t<T>&, const remove_reference_t<U>&> &&
totally_ordered<
common_reference_t<
const remove_reference_t<T>&,
const remove_reference_t<U>&>> &&
equality_comparable_with<T, U> &&
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;
};
Концепт 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 equivalence_relation = relation<R, T, U>;
Концепт strict_weak_order
template<class R, class T, class U>
concept strict_weak_order = relation<R, T, U>;