标准库头文件 <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 亦为 EqualityComparable (概念) |
可调用概念 | |
| (C++20) |
指定能以给定的一组实参类型调用的可调用类型 (概念) |
| (C++20) |
指定可调用类型为布尔谓词 (概念) |
| (C++20) |
指定可调用类型为二元关系 (概念) |
| (C++20) |
指定一个 Relation 所强加的是严格弱序 (概念) |
定制点对象 | |
| (C++20) |
交换两个对象的值 (定制点对象) |
[编辑] 概要
namespace std { // 核心语言概念 template <class T, class U> concept Same = /* 见说明 */; template <class Derived, class Base> concept DerivedFrom = /* 见说明 */; template <class From, class To> concept ConvertibleTo = /* 见说明 */; template <class T, class U> concept CommonReference = /* 见说明 */; template <class T, class U> concept Common = /* 见说明 */; template <class T> concept Integral = /* 见说明 */; template <class T> concept SignedIntegral = /* 见说明 */; template <class T> concept UnsignedIntegral = /* 见说明 */; template <class LHS, class RHS> concept Assignable = /* 见说明 */; namespace ranges { inline namespace /* 未指明 */ { inline constexpr /* 未指明 */ swap = /* 未指明 */; } } template <class T> concept Swappable = /* 见说明 */; template <class T, class U> concept SwappableWith = /* 见说明 */; template <class T> concept Destructible = /* 见说明 */; template <class T, class... Args> concept Constructible = /* 见说明 */; template <class T> concept DefaultConstructible = /* 见说明 */; template <class T> concept MoveConstructible = /* 见说明 */; template <class T> concept CopyConstructible = /* 见说明 */; // 比较概念 template <class B> concept Boolean = /* 见说明 */; template <class T> concept EqualityComparable = /* 见说明 */; template <class T, class U> concept EqualityComparableWith = /* 见说明 */; template <class T> concept StrictTotallyOrdered = /* 见说明 */; template <class T, class U> concept StrictTotallyOrderedWith = /* 见说明 */; // 对象概念 template <class T> concept Movable = /* 见说明 */; template <class T> concept Copyable = /* 见说明 */; template <class T> concept Semiregular = /* 见说明 */; template <class T> concept Regular = /* 见说明 */; // 可调用概念 template <class F, class... Args> concept Invocable = /* 见说明 */; template <class F, class... Args> concept RegularInvocable = /* 见说明 */; template <class F, class... Args> concept Predicate = /* 见说明 */; template <class R, class T, class U> concept Relation = /* 见说明 */; template <class R, class T, class U> concept StrictWeakOrder = /* 见说明 */; }
[编辑] 概念 Same
template<class T, class U> concept __SameImpl = is_same_v<T, U>; // 仅为阐释 template<class T, class U> concept Same = __SameImpl<T, U> && __SameImpl<U, T>;
[编辑] 概念 DerivedFrom
template<class Derived, class Base> concept DerivedFrom = is_base_of_v<Base, Derived> && is_convertible_v<const volatile Derived*, const volatile Base*>;
[编辑] 概念 ConvertibleTo
template<class From, class To> concept ConvertibleTo = is_convertible_v<From, To> && requires(From (&f)()) { static_cast<To>(f()); };
[编辑] 概念 CommonReference
template<class T, class U> concept CommonReference = Same<common_reference_t<T, U>, common_reference_t<U, T>> && ConvertibleTo<T, common_reference_t<T, U>> && ConvertibleTo<U, common_reference_t<T, U>>;
[编辑] 概念 Common
template<class T, class U> concept Common = Same<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>()); } && CommonReference< add_lvalue_reference_t<const T>, add_lvalue_reference_t<const U>> && CommonReference< 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>;
[编辑] 概念 SignedIntegral
template<class T> concept SignedIntegral = Integral<T> && is_signed_v<T>;
[编辑] 概念 UnsignedIntegral
template<class T> concept UnsignedIntegral = Integral<T> && !SignedIntegral<T>;
[编辑] 概念 Assignable
template<class LHS, class RHS> concept Assignable = is_lvalue_reference_v<LHS> && CommonReference<const remove_reference_t<LHS>&, const remove_reference_t<RHS>&> && requires(LHS lhs, RHS&& rhs) { { lhs = std::forward<RHS>(rhs) } -> Same<LHS>; };
[编辑] 概念 Swappable
template<class T> concept Swappable = requires(T& a, T& b) { ranges::swap(a, b); };
[编辑] 概念 SwappableWith
template<class T, class U> concept SwappableWith = CommonReference<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
template<class T, class... Args> concept Constructible = Destructible<T> && is_constructible_v<T, Args>;
[编辑] 概念 DefaultConstructible
template<class T> concept DefaultConstructible = Constructible<T>;
[编辑] 概念 MoveConstructible
template<class T> concept MoveConstructible = Constructible<T, T> && ConvertibleTo<T, T>;
[编辑] 概念 CopyConstructible
template<class T> concept CopyConstructible = MoveConstructible<T> && Constructible<T, T&> && ConvertibleTo<T&, T> && Constructible<T, const T&> && ConvertibleTo<const T&, T> && Constructible<T, const T> && ConvertibleTo<const T, T>;
[编辑] 概念 Boolean
template<class B> concept Boolean = Movable<remove_cvref_t<B>> && requires(const remove_reference_t<B>& b1, const remove_reference_t<B>& b2, const bool a) { requires ConvertibleTo<const remove_reference_t<B>&, bool>; { !b1 } -> ConvertibleTo<bool>; { b1 && b2 } -> Same<bool>; { b1 && a } -> Same<bool>; { a && b2 } -> Same<bool>; { b1 || b2 } -> Same<bool>; { b1 || a } -> Same<bool>; { a || b2 } -> Same<bool>; { b1 == b2 } -> ConvertibleTo<bool>; { b1 == a } -> ConvertibleTo<bool>; { a == b2 } -> ConvertibleTo<bool>; { b1 != b2 } -> ConvertibleTo<bool>; { b1 != a } -> ConvertibleTo<bool>; { a != b2 } -> ConvertibleTo<bool>; };
[编辑] 概念 EqualityComparable
template<class T, class U> concept __WeaklyEqualityComparableWith = // 仅为阐释 requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) { { t == u } -> Boolean; { t != u } -> Boolean; { u == t } -> Boolean; { u != t } -> Boolean; }; template<class T> concept EqualityComparable = __WeaklyEqualityComparableWith<T, T>;
[编辑] 概念 EqualityComparableWith
template<class T, class U> concept EqualityComparableWith = EqualityComparable<T> && EqualityComparable<U> && CommonReference<const remove_reference_t<T>&, const remove_reference_t<U>&> && EqualityComparable< common_reference_t< const remove_reference_t<T>&, const remove_reference_t<U>&>> && __WeaklyEqualityComparableWith<T, U>;
[编辑] 概念 StrictTotallyOrdered
template<class T> concept StrictTotallyOrdered = EqualityComparable<T> && requires(const remove_reference_t<T>& a, const remove_reference_t<T>& b) { { a < b } -> Boolean; { a > b } -> Boolean; { a <= b } -> Boolean; { a >= b } -> Boolean; };
[编辑] 概念 StrictTotallyOrderedWith
template<class T, class U> concept StrictTotallyOrderedWith = StrictTotallyOrdered<T> && StrictTotallyOrdered<U> && CommonReference<const remove_reference_t<T>&, const remove_reference_t<U>&> && StrictTotallyOrdered< common_reference_t< const remove_reference_t<T>&, const remove_reference_t<U>&>> && EqualityComparableWith<T, U> && requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) { { t < u } -> Boolean; { t > u } -> Boolean; { t <= u } -> Boolean; { t >= u } -> Boolean; { u < t } -> Boolean; { u > t } -> Boolean; { u <= t } -> Boolean; { u >= t } -> Boolean; };
[编辑] 概念 Movable
template<class T> concept Movable = is_object_v<T> && MoveConstructible<T> && Assignable<T&, T> && Swappable<T>;
[编辑] 概念 Copyable
template<class T> concept Copyable = CopyConstructible<T> && Movable<T> && Assignable<T&, const T&>;
[编辑] 概念 Semiregular
template<class T> concept Semiregular = Copyable<T> && DefaultConstructible<T>;
[编辑] 概念 Regular
template<class T> concept Regular = Semiregular<T> && EqualityComparable<T>;
[编辑] 概念 Invocable
template<class F, class... Args> concept Invocable = requires(F&& f, Args&&... args) { invoke(std::forward<F>(f), std::forward<Args>(args)...); // 不要求维持相等性 };
[编辑] 概念 RegularInvocable
template<class F, class... Args> concept RegularInvocable = Invocable<F, Args...>;
[编辑] 概念 Predicate
template<class F, class... Args> concept Predicate = RegularInvocable<F, Args...> && Boolean<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>;
[编辑] 概念 StrictWeakOrder
template<class R, class T, class U> concept StrictWeakOrder = Relation<R, T, U>;

