Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | named req
m (fix redlink)
(match std)
Line 2: Line 2:
 
{{cpp/concept/navbar}}
 
{{cpp/concept/navbar}}
  
Specifies that an instance of the type can be copy-assigned (copied).
+
Specifies that an instance of the type can be copy-assigned.
 
+
This concept implies {{concept|MoveAssignable}}.
+
  
 
===Requirements===
 
===Requirements===
  
The type must implement the following functions:
+
The type {{tt|T}} satisfies {{tt|CopyAssignable}} if
 
+
{{member | 1={{dsc small|Type::}}operator= | 2=
+
  
{{ddcl | notes={{mark|One of the variants is sufficient}} | 1=
+
* The type {{tt|T}} satisfies {{concept|MoveAssignable}}, and
Type& Type::operator=( Type& other );
+
Type& Type::operator=( const Type& other );
+
Type& Type::operator=( volatile Type& other );
+
Type& Type::operator=( const volatile Type& other );
+
}}
+
  
[[cpp/language/as_operator|Copy assignment operator]]: assigns the contents of {{tt|other}}. The internal state of {{tt|other}} must not be modified.
+
Given
 +
* {{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 following expressions must have the specified effects:
+
The following expressions must be valid and have their specified effects
  
{{dsc begin}}
+
{|table class=wikitable
{{dsc hitem | Expression | Effects}}
+
|-
{{dsc | {{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.}}
+
!Expression||Return type||Return value||Post-conditions
{{dsc end}}
+
|-
}}
+
| {{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.
 +
|}
  
 
===See also===
 
===See also===

Revision as of 12:00, 28 December 2013

Template:cpp/concept/title Template:cpp/concept/navbar

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

Requirements

The type T satisfies CopyAssignable if

Given

  • v, an lvalue expression of type T or const T or an rvalue expression of type const T

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.

See also

checks if a type has a copy assignment operator
(class template) [edit]