Overview of Move Semantics¶
Move semantics transfer an object's owned state instead of copying it. In
Quxlang, a move constructor receives the source as TEMP&:
The source remains a live object after the constructor and will still be destroyed. The move constructor must leave it in a safe moved-from state.
Forwarding a reference category¶
Generic code uses FORWARD(name) to preserve whether a reference is mutable,
constant, or temporary:
FORWARD does not move by itself. It passes the reference category onward so a
later call can choose a copy or move overload.
Movement semantics¶
destination := source; assigns an existing object. Constructing a new object
from a forwarded temporary is what selects a move constructor:
Relocatable structures¶
STRUCT TRIVIALLY_RELOCATABLE permits the compiler to transfer an object by
copying its representation and transferring its lifetime. Ordinary copies keep
their copy-constructor behavior. Templates can select the promise with
TRIVIALLY_RELOCATABLE_IF(condition). See the
relocation contract.
Reference¶
For TEMP&, forwarding constraints, moved-from lifetime, and generated move
rules, see the Move Semantics Reference.