Files
2025-10-25 03:02:53 +03:00

2.4 KiB
Raw Permalink Blame History

[concept.assignable]

18 Concepts library [concepts]

18.4.8 Concept assignable_from [concept.assignable]

🔗

template<class LHS, class RHS> concept [assignable_from](#concept:assignable_from "18.4.8Concept assignable_­from[concept.assignable]") = is_lvalue_reference_v<LHS> && [common_reference_with](concept.commonref#concept:common_reference_with "18.4.5Concept common_­reference_­with[concept.commonref]")<const remove_reference_t<LHS>&, const remove_reference_t<RHS>&> && requires(LHS lhs, RHS&& rhs) { { lhs = std::forward<RHS>(rhs) } -> [same_as](concept.same#concept:same_as "18.4.2Concept same_­as[concept.same]")<LHS>; };

1

#

Let:

lhs be an lvalue that refers to an object lcopy such that decltype((lhs)) is LHS,

rhs be an expression such that decltype((rhs)) is RHS, and

rcopy be a distinct object that is equal to rhs.

LHS and RHS modelassignable_from<LHS, RHS> only if

  • (1.4)

    addressof(lhs = rhs) == addressof(lcopy).

  • (1.5)

    After evaluating lhs = rhs:

    • (1.5.1)

      lhs is equal to rcopy, unless rhs is a non-const xvalue that refers to lcopy.

    • (1.5.2)

      If rhs is a non-const xvalue, the resulting state of the object to which it refers is valid but unspecified ([lib.types.movedfrom]).

    • (1.5.3)

      Otherwise, if rhs is a glvalue, the object to which it refers is not modified.

2

#

[Note 1:

Assignment need not be a total function ([structure.requirements]); in particular, if assignment to an object x can result in a modification of some other object y, then x = y is likely not in the domain of =.

— end note]