[include(틀:상위 문서, top1=C++)] [목차] == 개요 == {{{+3 [[https://en.cppreference.com/w/cpp/concepts|#]] '''제약조건''' }}} ==# 모듈 요약 코드 #== {{{#!syntax cpp namespace std { // language-related concepts template concept same_as = is_same_v && is_same_v; template concept derived_from = is_base_of_v && is_convertible_v; template concept convertible_to = is_convertible_v && requires(From (&from)()) { static_cast(from()); // std::declval() }; template concept common_reference_with = same_as, common_reference_t> && convertible_to> && convertible_to>; template concept common_with = same_as, common_type_t> && requires { static_cast>(declval()); static_cast>(declval()); } && common_reference_with, add_lvalue_reference_t> && common_reference_with>, common_reference_t, add_lvalue_reference_t>>; // arithmetic concepts template concept integral = is_integral_v; template concept signed_integral = integral && is_signed_v; template concept unsigned_integral = integral && !signed_integral; template concept floating_point = is_floating_point_v; template concept assignable_from = is_lvalue_reference_v && common_reference_with&, const remove_reference_t&> && requires(LHS lhs, RHS&& rhs) { { lhs = std::forward(rhs) } -> same_as; } namespace ranges { inline namespace /* unspecified */ { inline constexpr /* unspecified */ swap = /* unspecified */; } } template concept swappable = requires(T& a, T& b) { ranges::swap(a, b); }; template concept swappable_with = common_reference_with&, const remove_reference_t&> && requires(T&& t, U&& u) { ranges::swap(std::forward(t), std::forward(t)); ranges::swap(std::forward(u), std::forward(u)); ranges::swap(std::forward(t), std::forward(u)); ranges::swap(std::forward(u), std::forward(t)); }; template concept destructible = is_nothrow_destructible_v; template concept constructible_from = destructible && is_constructible_v; template concept default_initializable = /* --- */; template concept move_constructible = constructible_from && convertible_to; template concept copy_constructible = move_constructible && constructible_from && convertible_to && constructible_from && convertible_to && constructible_from && convertible_to; // comparison concepts template concept __WeaklyEqualityComparableWith = // 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 = __WeaklyEqualityComparableWith; template concept equality_comparable = /* see description */; template concept equality_comparable_with = equality_comparable && equality_comparable && common_reference_with&, const remove_reference_t&> && equality_comparable&, const remove_reference_t&>> && __WeaklyEqualityComparableWith; template concept totally_ordered = equality_comparable && requires(const remove_reference_t& a, const remove_reference_t& b) { { a < b } -> boolean-testable; { a > b } -> boolean-testable; { a <= b } -> boolean-testable; { a >= b } -> boolean-testable; }; template concept totally_ordered_with = totally_ordered && totally_ordered && common_reference_with&, const remove_reference_t&> && totally_ordered&, const remove_reference_t&>> && equality_comparable_with && requires(const remove_reference_t& t, const remove_reference_t& 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; }; // object concepts template concept movable = is_object_v && move_constructible && assignable_from && swappable; template concept copyable = copy_constructible && movable && assignable_from && assignable_from && assignable_from; template concept semiregular = copyable && default_initializable; template concept regular = semiregular && equality_comparable; // callable concepts template concept invocable = requires(F&& f, Args&&... args) { std::invoke(std::forward(f), std::forward(args)...); }; template concept regular_invocable = invocable; template concept predicate = regular_invocable && boolean-testable>; template concept relation = predicate && predicate && predicate && predicate; template concept equivalence_relation = relation; template concept strict_weak_order = relation; } }}} == 설명 == == 예제 == ## 작성중... [각주] [[분류:프로그래밍 언어 문법]]