# std::assignable_from

< cpp‎ | concepts

C++
 Compiler support Freestanding and hosted Language Standard library headers Named requirements Feature test macros (C++20) Language support library Concepts library (C++20) Diagnostics library General utilities library Strings library Containers library Iterators library Ranges library (C++20) Algorithms library Numerics library Localizations library Input/output library Filesystem library (C++17) Regular expressions library (C++11) Atomic operations library (C++11) Thread support library (C++11) Technical specifications Symbols index External libraries

Concepts library
 Comparison concepts equality_comparableequality_comparable_with totally_orderedtotally_ordered_with Object concepts movable copyable semiregular regular Callable concepts invocableregular_invocable predicate relation equivalence_relation strict_weak_order

 Defined in header  template< class LHS, class RHS > concept assignable_from =   std::is_lvalue_reference_v &&   std::common_reference_with<     const std::remove_reference_t&,     const std::remove_reference_t&> &&   requires(LHS lhs, RHS&& rhs) {     { lhs = std::forward(rhs) } -> std::same_as;   }; (since C++20)

The concept assignable_from<LHS, RHS> specifies that an expression of the type and value category specified by RHS can be assigned to an lvalue expression whose type is specified by LHS.

## Contents

###  Semantic requirements

Given

• lhs, an lvalue that refers to an object lcopy such that decltype((lhs)) is LHS,
• rhs, an expression such that decltype((rhs)) is RHS,
• rcopy, a distinct object that is equal to rhs,

assignable_from<LHS, RHS> is modeled only if

• std::addressof(lhs = rhs) == std::addressof(lcopy) (i.e., the assignment expression yields an lvalue referring to the left operand);
• After evaluating lhs = rhs:
• lhs is equal to rcopy, unless rhs is a non-const xvalue that refers to lcopy (i.e., the assignment is a self-move-assignment),
• if rhs is a glvalue:
• If it is a non-const xvalue, the object to which it refers is in a valid but unspecified state;
• Otherwise, the object it refers to is not modified;

###  Equality preservation

An expression is equality preserving if it results in equal outputs given equal inputs.

• The inputs to an expression consist of its operands.
• The outputs of an expression consist of its result and all operands modified by the expression (if any).

In specification of standard concepts, operands are defined as the largest subexpressions that include only:

The cv-qualification and value category of each operand is determined by assuming that each template type parameter denotes a cv-unqualified complete non-array object type.

Every expression required to be equality preserving is further required to be stable: two evaluations of such an expression with the same input objects must have equal outputs absent any explicit intervening modification of those input objects.

Unless noted otherwise, every expression used in a requires-expression is required to be equality preserving and stable, and the evaluation of the expression may only modify its non-constant operands. Operands that are constant must not be modified.

###  Notes

Assignment need not be a total function. In particular, if assigning to some object x can cause some other object y to be modified, then x = y is likely not in the domain of =. This typically happens if the right operand is owned directly or indirectly by the left operand (e.g., with smart pointers to nodes in an node-based data structure, or with something like ).