标准库头文件 <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 = /* 见描述 */; 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>;