std::experi...::Assignable(3)
π NAME π
Welcome to std::experi...::Assignable(3) from the C++ Standard Libary, aka std::experimental::ranges::Assignable β yes bestie, the concept is literally named the same thing twice, it's giving "the name is the name" π
.
β¨ Synopsis β¨
Okay so first things first: it's Defined in header <experimental/ranges/concepts> and the whole thing looks like this, no cap:
template< class T, class U >
concept bool Assignable =
std::is_lvalue_reference<T>::value &&
CommonReference<
const std::remove_reference_t<T>&, (ranges TS)
const std::remove_reference_t<U>&> &&
requires(T t, U&& u) {
{ t = std::forward<U>(u) } -> Same<T>&&;
};
The concept Assignable<T, U> specifies that an expression of the type and value category specified by U can be assigned to an lvalue expression whose type is specified by T. Slay, that's the whole vibe πΈ.
Given:
t, an lvalue of typestd::remove_reference_t<T>that refers to an objecto,u, an expression such thatdecltype((u))isU,u2, a distinct object that is equal tou,
Assignable<T, U> is satisfied only if:
std::addressof(t = u) == std::addressof(o)(i.e., the assignment expression yields an lvalue referring to the left operand);- After evaluating
t = u:tis equal tou2, unlessuis a non-const xvalue that refers too(i.e., the assignment is a self-move-assignment),- if
uis 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;
There need not be any subsumption relationship between Assignable<T, U> and std::is_lvalue_reference<T>::value. Not me pointing that out, it's just in the specs bestie π.
π¦ 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).
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. Periodt π«Ά.
π Notes π
A deduction constraint of the form { expression } -> Same<T>&& effectively requires decltype((expression))&& to be the exact same type as T&&. This constrains both the expression's type and its value category. It's giving very precise, very iconic π₯.
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 a node-based data structure, or with something like std::vector<std::any>). So yeah, watch out for that self-own situation bestie ππ.
Source/version/date vibes: http://cppreference.com, 2024.06.10, std::experi...::Assignable(3) β stay assignable, stay iconic, mwah πβ¨π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms