Standard library header (C++20) (original) (raw)
This header is part of the concepts library.
[edit] Synopsis
// all freestanding namespace std { // language-related concepts // concept same_as template<class T, class U> concept same_as = /* see description /; // concept derived_from template<class Derived, class Base> concept derived_from = / see description /; // concept convertible_to template<class From, class To> concept convertible_to = / see description /; // concept common_reference_with template<class T, class U> concept common_reference_with = / see description /; // concept common_with template<class T, class U> concept common_with = / see description /; // arithmetic concepts template concept integral = / see description /; template concept signed_integral = / see description /; template concept unsigned_integral = / see description /; template concept floating_point = / see description /; // concept assignable_from template<class LHS, class RHS> concept assignable_from = / see description /; // concept swappable namespace ranges { inline namespace / unspecified / { inline constexpr / unspecified / swap = / unspecified /; } } template concept swappable = / see description /; template<class T, class U> concept swappable_with = / see description /; // concept destructible template concept destructible = / see description /; // concept constructible_from template<class T, class... Args> concept constructible_from = / see description /; // concept default_initializable template concept default_initializable = / see description /; // concept move_constructible template concept move_constructible = / see description /; // concept copy_constructible template concept copy_constructible = / see description /; // comparison concepts // concept equality_comparable template concept equality_comparable = / see description /; template<class T, class U> concept equality_comparable_with = / see description /; // concept totally_ordered template concept totally_ordered = / see description /; template<class T, class U> concept totally_ordered_with = / see description /; // object concepts template concept movable = / see description /; template concept copyable = / see description /; template concept semiregular = / see description /; template concept regular = / see description /; // callable concepts // concept invocable template<class F, class... Args> concept invocable = / see description /; // concept regular_invocable template<class F, class... Args> concept regular_invocable = / see description /; // concept predicate template<class F, class... Args> concept predicate = / see description /; // concept relation template<class R, class T, class U> concept relation = / see description /; // concept equivalence_relation template<class R, class T, class U> concept equivalence_relation = / see description /; // concept strict_weak_order template<class R, class T, class U> concept strict_weak_order = / see description */; }
[edit] Helper concept boolean-testable
template
concept /boolean-testable-impl/ = convertible_to<T, bool>; // exposition only;
template
concept boolean-testable = // exposition only
/boolean-testable-impl/ && requires(T&& t) {
{
(t)
} -> /boolean-testable-impl/;
};
[edit] Concept same_as
template<class T, class U> concept /same-as-impl/ = is_same_v<T, U>; // exposition only template<class T, class U> concept same_as = /same-as-impl/<T, U> && /same-as-impl/<U, T>;
[edit] Concept 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*>;
[edit] Concept convertible_to
template<class From, class To> concept convertible_to = is_convertible_v<From, To> && requires { static_cast(declval()); };
[edit] Concept 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>>;
[edit] Concept 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()); static_cast<common_type_t<T, U>>(declval()); } && common_reference_with<add_lvalue_reference_t, add_lvalue_reference_t> && common_reference_with< add_lvalue_reference_t<common_type_t<T, U>>, common_reference_t<add_lvalue_reference_t, add_lvalue_reference_t>>;
[edit] Concept integral
template concept integral = is_integral_v;
[edit] Concept signed_integral
template concept signed_integral = integral && is_signed_v;
[edit] Concept unsigned_integral
template concept unsigned_integral = integral && !signed_integral;
[edit] Concept floating_point
template concept floating_point = is_floating_point_v;
[edit] Concept assignable_from
template<class LHS, class RHS> concept assignable_from = is_lvalue_reference_v && common_reference_with<const remove_reference_t&, const remove_reference_t&> && requires(LHS lhs, RHS&& rhs) { { lhs = std::forward(rhs) } -> same_as; };
[edit] Concept swappable
template concept swappable = requires(T& a, T& b) { ranges::swap(a, b); };
[edit] Concept swappable_with
[edit] Concept destructible
template concept destructible = is_nothrow_destructible_v;
[edit] Concept constructible_from
template<class T, class... Args> concept constructible_from = destructible && is_constructible_v<T, Args...>;
[edit] Concept default_initializable
template constexpr bool /is-default-initializable/ = /* see description */; // exposition only template concept default_initializable = constructible_from && requires { T{}; } && /is-default-initializable/;
[edit] Concept move_constructible
template concept move_constructible = constructible_from<T, T> && convertible_to<T, T>;
[edit] Concept copy_constructible
template concept copy_constructible = move_constructible && 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>;
[edit] Concept equality_comparable
template<class T, class U> concept /weakly-equality-comparable-with/ = // exposition only requires(const remove_reference_t& t, const remove_reference_t& u) { { t == u } -> boolean-testable; { t != u } -> boolean-testable; { u == t } -> boolean-testable; { u != t } -> boolean-testable; }; template concept equality_comparable = /weakly-equality-comparable-with/<T, T>;
[edit] Concept equality_comparable_with
template<class T, class U, class C = common_reference_t<const T&, const U&>> concept /comparison-common-type-with-impl/ = // exposition only 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/ = // exposition only /comparison-common-type-with-impl/<remove_cvref_t, remove_cvref_t>; template<class T, class U> concept equality_comparable_with = equality_comparable && equality_comparable && /comparison-common-type-with/<T, U> && equality_comparable< common_reference_t<const remove_reference_t&, const remove_reference_t&>> && /weakly-equality-comparable-with/<T, U>;
[edit] Helper concept partially-ordered-with
[edit] Concept totally_ordered
template concept totally_ordered = equality_comparable && /partially-ordered-with/<T, T>;
[edit] Concept totally_ordered_with
template<class T, class U> concept totally_ordered_with = totally_ordered && totally_ordered && equality_comparable_with<T, U> && totally_ordered< common_reference_t<const remove_reference_t&, const remove_reference_t&>> && /partially-ordered-with/<T, U>;
[edit] Concept movable
template concept movable = is_object_v && move_constructible && assignable_from<T&, T> && swappable;
[edit] Concept copyable
template concept copyable = copy_constructible && movable && assignable_from<T&, T&> && assignable_from<T&, const T&> && assignable_from<T&, const T>;
[edit] Concept semiregular
template concept semiregular = copyable && default_initializable;
[edit] Concept regular
template concept regular = semiregular && equality_comparable;
[edit] Concept invocable
template<class F, class... Args> concept invocable = requires(F&& f, Args&&... args) { invoke(std::forward(f), std::forward(args)...); // not required to be equality-preserving };
[edit] Concept regular_invocable
template<class F, class... Args> concept regular_invocable = invocable<F, Args...>;
[edit] Concept predicate
template<class F, class... Args> concept predicate = regular_invocable<F, Args...> && boolean-testable<invoke_result_t<F, Args...>>;
[edit] Concept 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>;
[edit] Concept equivalence_relation
template<class R, class T, class U> concept equivalence_relation = relation<R, T, U>;
[edit] Concept strict_weak_order
template<class R, class T, class U> concept strict_weak_order = relation<R, T, U>;