Difference between revisions of "cpp/named req/MoveAssignable"
From cppreference.com
(→Requirements: LWG2468) |
Andreas Krug (Talk | contribs) m (fmt, .) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | {{cpp/ | + | {{cpp/named req/title|MoveAssignable|notes={{mark since c++11}}}} |
− | {{cpp/ | + | {{cpp/named req/navbar}} |
Specifies that an instance of the type can be assigned from an [[cpp/language/value_category|rvalue]] argument. | Specifies that an instance of the type can be assigned from an [[cpp/language/value_category|rvalue]] argument. | ||
===Requirements=== | ===Requirements=== | ||
− | The type {{tt|T}} satisfies {{ | + | The type {{tt|T}} satisfies {{named req/core|MoveAssignable}} if |
Given | Given | ||
− | * {{tt|t}}, a modifiable [[cpp/language/value_category|lvalue expression]] of type {{tt|T}} | + | * {{tt|t}}, a modifiable [[cpp/language/value_category|lvalue expression]] of type {{tt|T}}, |
− | * {{tt|rv}}, an [[cpp/language/value_category|rvalue]] expression of type {{tt|T}} | + | * {{tt|rv}}, an [[cpp/language/value_category|rvalue]] expression of type {{tt|T}}. |
− | The following expressions must be valid and have their specified effects | + | The following expressions must be valid and have their specified effects. |
{|table class=wikitable | {|table class=wikitable | ||
Line 17: | Line 17: | ||
!Expression||Return type||Return value||Post-conditions | !Expression||Return type||Return value||Post-conditions | ||
|- | |- | ||
− | | {{c|1=t = rv}} | + | |{{c|1=t = rv}} |
− | | {{tt|T&}} | + | |{{tt|T&}} |
− | | {{tt|t}} | + | |{{tt|t}} |
− | | If {{tt|t}} and {{tt|rv}} do not refer to the same object | + | |If {{tt|t}} and {{tt|rv}} do not refer to the same object{{mark unreviewed dr|LWG|2468}}, the value of {{tt|t}} is equivalent to the value of {{tt|rv}} before the assignment. |
− | The new value of {{tt|rv}} is unspecified | + | The new value of {{tt|rv}} is unspecified. |
|} | |} | ||
Line 27: | Line 27: | ||
The type does not have to implement [[cpp/language/move_operator|move assignment operator]] in order to satisfy this type requirement: a [[cpp/language/as_operator|copy assignment operator]] that takes its parameter by value or as a {{tt|const Type&}}, will bind to rvalue argument. | The type does not have to implement [[cpp/language/move_operator|move assignment operator]] in order to satisfy this type requirement: a [[cpp/language/as_operator|copy assignment operator]] that takes its parameter by value or as a {{tt|const Type&}}, will bind to rvalue argument. | ||
− | If a MoveAssignable class implements a move assignment operator, it may also implement [[cpp/utility/move|move semantics]] to take advantage of the fact that the value of {{tt|rv}} after assignment is unspecified. | + | If a {{named req/core|MoveAssignable}} class implements a move assignment operator, it may also implement [[cpp/utility/move|move semantics]] to take advantage of the fact that the value of {{tt|rv}} after assignment is unspecified. |
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc inc | cpp/types/dsc is_move_assignable}} | + | {{dsc inc|cpp/types/dsc is_move_assignable}} |
+ | {{dsc inc|cpp/concepts/dsc assignable_from}} | ||
{{dsc end}} | {{dsc end}} | ||
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 10:40, 8 August 2023
Specifies that an instance of the type can be assigned from an rvalue argument.
[edit] Requirements
The type T
satisfies MoveAssignable if
Given
-
t
, a modifiable lvalue expression of typeT
, -
rv
, an rvalue expression of typeT
.
The following expressions must be valid and have their specified effects.
Expression | Return type | Return value | Post-conditions |
---|---|---|---|
t = rv | T&
|
t
|
If t and rv do not refer to the same object, the value of t is equivalent to the value of rv before the assignment.
The new value of |
[edit] Notes
The type does not have to implement move assignment operator in order to satisfy this type requirement: a copy assignment operator that takes its parameter by value or as a const Type&
, will bind to rvalue argument.
If a MoveAssignable class implements a move assignment operator, it may also implement move semantics to take advantage of the fact that the value of rv
after assignment is unspecified.
[edit] See also
(C++11)(C++11)(C++11) |
checks if a type has a move assignment operator (class template) |
(C++20) |
specifies that a type is assignable from another type (concept) |