Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | named req
(Requirements)
Line 11: Line 11:
  
 
{{ddcl | notes={{mark|One of the variants is sufficient}} | 1=
 
{{ddcl | notes={{mark|One of the variants is sufficient}} | 1=
Type& Type::operator=( Type&& other );
+
Type& Type::operator=( Type& other );
Type& Type::operator=( const Type&& other );
+
Type& Type::operator=( const Type& other );
Type& Type::operator=( volatile Type&& other );
+
Type& Type::operator=( volatile Type& other );
Type& Type::operator=( const volatile Type&& other );
+
Type& Type::operator=( const volatile Type& other );
 
}}
 
}}
  
[[cpp/language/move_operator|Move assignment operator]]: assigns the contents of {{tt|other}}. The internal state of {{tt|other}} is unspecified after the move. However, it must still be valid, that is, no invariants of the type are broken. The function must return {{tt|*this}}.
+
[[cpp/language/copy_operator|Copy assignment operator]]: assigns the contents of {{tt|other}}. The internal state of {{tt|other}} must not be modified.
  
 
The following expressions must have the specified effects:
 
The following expressions must have the specified effects:
Line 23: Line 23:
 
{{tdcl list begin}}
 
{{tdcl list begin}}
 
{{tdcl list hitem | Expression | Effects}}
 
{{tdcl list hitem | Expression | Effects}}
{{tdcl list item | {{cpp|1=a = rv;}} | {{tt|a}} is equivalent to {{tt|rv}}, where {{tt|a}} is an instance of {{tt|Type}} and {{tt|rv}} is a [[todo|rvalue reference]] of {{tt|Type}}.}}
+
{{tdcl list item | {{cpp|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}}
 
{{tdcl list end}}
 
}}
 
}}

Revision as of 06:56, 11 March 2012

Template:cpp/concept/title Template:cpp/concept/sidebar

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

Requirements

The type must implement the following functions:

Type::operator=

Type& Type::operator=( Type& other );

Type& Type::operator=( const Type& other );
Type& Type::operator=( volatile Type& other );

Type& Type::operator=( const volatile Type& other );
(One of the variants is sufficient)

Copy assignment operator: assigns the contents of other. The internal state of other must not be modified.

The following expressions must have the specified effects:

Template:tdcl list begin Template:tdcl list hitem Template:tdcl list item Template:tdcl list end