Assignable | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
Detailed Description
A type is Assignable if it is possible to copy objects of that type and to assign values to variables.
- Refinement Of:
- Associated Types:
- Notation:
XA type that is a model of Assignable x,yObject of type X
- Definitions:
- Valid Expressions:
Name Expression Type requirements Return type Copy constructor X(x)XCopy constructor X x(y); X x = y;
Assignment x = y[1]X&Swap adobe::swap(x,y)void
- Expression Semantics:
Name Expression Precondition Semantics Postcondition Copy constructor X(x)X(x)is a copy ofx[2]Copy constructor X(x)X(x)is a copy ofx[2]Copy constructor X x(y); X x = y;
xis a copy ofy[2]Assignment x=y[1]xis a copy ofy[2]Swap adobe::swap(x,y)[3]Equivalent to { X tmp = x; x = y; y = tmp; }
- Complexity Guarantees:
- Invariants:
- Type(s) Modeling this Concept:
- int
- Notes:
- [1] One implication of this requirement is that a
consttype is not Assignable. For example,const intis not Assignable: ifxis declared to be of typeconst int, thenx = 7is illegal. Similarly, the typepair<const int, int>is not Assignable.
- [2] The reason this says "
xis a copy ofy", rather than "x == y", is thatoperator==is not necessarily defined: equality is not a requirement of Assignable. If the typeXis EqualityComparable as well as Assignable, then a copy ofxshould compare equal tox.
- [3]
adobe::swapwill not throw an exception for an assignable type. For types with remote parts,adobe::swapmust be specialized to swap the remote parts.
- [4] It is assumed that adobe::swap() will not throw an exception. Items with remote parts much specialize swap as described in swap.
- See Also:

