Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | named req
m (Text replace - "{{cpp|" to "{{c|")
m (fmt, .)
 
(16 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{cpp/concept/title|CopyAssignable}}
+
{{cpp/named req/title|CopyAssignable}}
{{cpp/concept/sidebar}}
+
{{cpp/named req/navbar}}
  
Specifies that an instance of the type can be copy-assigned (copied).
+
Specifies that an instance of the type can be copy-assigned from an [[cpp/language/value_category|lvalue expression]].
 
+
This concept implies {{concept|MoveAssignable}}.
+
  
 
===Requirements===
 
===Requirements===
 +
The type {{tt|T}} satisfies {{named req/core|CopyAssignable}} if
 +
* The type {{tt|T}} satisfies {{named req|MoveAssignable}}, and
 +
Given
 +
* {{tt|t}}, a modifiable [[cpp/language/value_category|lvalue expression]] of type {{tt|T}},
 +
* {{tt|v}}, an [[cpp/language/value_category|lvalue]] expression of type {{tt|T}} or {{tt|const T}} or an [[cpp/language/value_category|rvalue]] expression of type {{tt|const T}}.
  
The type must implement the following functions:
+
The following expressions must be valid and have their specified effects.
  
{{member | 1={{dcl small|Type::}}operator= | 2=
+
{|table class=wikitable
 +
|-
 +
!Expression||Return type||Return value||Post-conditions
 +
|-
 +
|{{c|1=t = v}}
 +
|{{tt|T&}}
 +
|{{tt|t}}
 +
|The value of {{tt|t}} is equivalent to the value of {{tt|v}}.
 +
The value of {{tt|v}} is unchanged.
 +
|}
  
{{ddcl | notes={{mark|One of the variants is sufficient}} | 1=
+
===See also===
Type& Type::operator=( Type& other );
+
{{dsc begin}}
Type& Type::operator=( const Type& other );
+
{{dsc inc|cpp/types/dsc is_copy_assignable}}
Type& Type::operator=( volatile Type& other );
+
{{dsc inc|cpp/concepts/dsc assignable_from}}
Type& Type::operator=( const volatile Type& other );
+
{{dsc end}}
}}
+
  
[[cpp/language/copy_operator|Copy assignment operator]]: assigns the contents of {{tt|other}}. The internal state of {{tt|other}} must not be modified.
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
 
+
The following expressions must have the specified effects:
+
 
+
{{tdcl list begin}}
+
{{tdcl list hitem | Expression | Effects}}
+
{{tdcl list item | {{c|1=a = v;}} | {{tt|a}} is equivalent to {{tt|v}}, where {{tt|a}} is an instance of {{tt|Type}} and {{tt|v}} is an instance of {{tt|Type}}. {{tt|v}} must be unchanged.}}
+
{{tdcl list end}}
+
}}
+
 
+
===See also===
+
{{dcl list begin}}
+
{{dcl list template | cpp/types/dcl list is_copy_assignable}}
+
{{dcl list end}}
+

Latest revision as of 10:36, 8 August 2023

 
 
C++ named requirements
 

Specifies that an instance of the type can be copy-assigned from an lvalue expression.

[edit] Requirements

The type T satisfies CopyAssignable if

Given

The following expressions must be valid and have their specified effects.

Expression Return type Return value Post-conditions
t = v T& t The value of t is equivalent to the value of v.

The value of v is unchanged.

[edit] See also

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