Книга: Standard Template Library Programmer
Concepts
Разделы на этой странице:
Assignable
Category: utilities
Component type: concept
Description
A type is Assignable if it is possible to copy objects of that type and to assign values to variables.
Notation
X
A type that is a model of Assignable
x, y
Object of type X
Valid expressions
Name | Expression | Return type |
---|---|---|
Copy constructor | X(x) |
X |
Copy constructor | X x(y); X x = y; |
|
Assignment | x = y [1] |
X& |
Swap | swap(x,y) |
void |
Expression semantics
Name | Expression | Semantics | Postcondition |
---|---|---|---|
Copy constructor | X(x) |
X(x) is a copy of x [2] | |
Copy constructor | X(x) |
X(x) is a copy of x [2] | |
Copy constructor | X x(y); X x = y; |
x is a copy of y [2] | |
Assignment | x = y [1] |
x is a copy of y [2] | |
Swap | swap (x,y) |
Equivalent to{ X tmp = x; x = y; y = tmp; } |
Models
• int
Notes
[1] One implication of this requirement is that a const type is not Assignable. For example, const int is not Assignable: if x is declared to be of type const int, then x = 7 is illegal. Similarly, the type pair<const int, int> is not Assignable.
[2] The reason this says "x is a copy of y ", rather than "x == y ", is that operator== is not necessarily defined: equality is not a requirement of Assignable. If the type X is EqualityComparable as well as Assignable, then a copy of x should compare equal to x.
See also
DefaultConstructible
Оглавление статьи/книги
Похожие страницы
- Basic X Concepts
- Essential DNS Concepts
- Concepts and Properties
- 8.1. Device Driver Concepts
- 9.1. Linux File System Concepts
- 1.3. HARDWARE CONCEPTS
- 1.4. SOFTWARE CONCEPTS
- 12.2 Version Control Concepts
- Concepts and Modeling
- 1.9 POSIX thread concepts
- Real-Time Concepts for Embedded Systems
- 8.5.2 Typical Condition Variable Operations