Adobe Systems Incorporated


Category: utilities Component type: concept


A type is Assignable if it is possible to copy objects of that type and to assign values to variables.

Refinement of

Associated types


X A type that is a model of Assignable
x, y Object of type X


Valid expressions

NameExpressionType requirementsReturn 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

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 adobe::swap(x,y)[3]   Equivalent to
  X tmp = x;
  x = y;
  y = tmp;

Complexity guarantees



  • int


[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.

[3] swap will not throw an exception for an assignable type. For types with remote parts, swap must be specialized to swap the remote parts. Please see the documentation on adobe::swap for more information.

[4] If assignment can throw an exception it must leave the value being assigned to untouched. For types with remote parts, this can be accomplished by implementing assignment as copy constructing a temp, and then swapping the temp with the value being assigned to. See the note adobe::swap().

See also


Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google