Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/named req/MoveAssignable"

From cppreference.com
< cpp‎ | named req
(Requirements: LWG2468)
m (fmt, .)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{cpp/concept/title|MoveAssignable {{mark since c++11}}}}
+
{{cpp/named req/title|MoveAssignable|notes={{mark since c++11}}}}
{{cpp/concept/navbar}}
+
{{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 {{tt|MoveAssignable}} if
+
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<!-- LWG 2468 -->, the value of {{tt|t}} is equivalent to the value of {{tt|rv}} before the assignment.
+
|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}}
  
[[de:cpp/concept/MoveAssignable]]
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
[[es:cpp/concept/MoveAssignable]]
+
[[fr:cpp/concept/MoveAssignable]]
+
[[it:cpp/concept/MoveAssignable]]
+
[[ja:cpp/concept/MoveAssignable]]
+
[[pt:cpp/concept/MoveAssignable]]
+
[[ru:cpp/concept/MoveAssignable]]
+
[[zh:cpp/concept/MoveAssignable]]
+

Latest revision as of 10:40, 8 August 2023

 
 
C++ named requirements
 

Specifies that an instance of the type can be assigned from an rvalue argument.

[edit] Requirements

The type T satisfies MoveAssignable if

Given

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 rv is unspecified.

[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

checks if a type has a move assignment operator
(class template) [edit]
specifies that a type is assignable from another type
(concept) [edit]