assign
var assign(var self, var obj);
Assign the object obj
to the object self
. The assigned object self
is returned.
Usage
var x = new(Int, $I(10));
var y = new(Int, $I(20));
show(x); /* 10 */
show(y); /* 20 */
assign(x, y);
show(x); /* 20 */
show(y); /* 20 */
Assignment
Assign
is potentially the most important class in Cello. It is used throughout Cello to initialise objects using other objects. In C++ this is called the copy constructor and it is used to assign the value of one object to another.
By default the Assign
class uses the Size
class to copy the memory from one object to another. But for more complex objects which maintain their own behaviours and state this may need to be overridden.
The most important thing about the Assign
class is that it must work on the assumption that the target object may not have had it's constructor called and could be uninitialised with just zero'd memory. This is often the case when copying contents into containers.
struct Assign {
void (*assign)(var, var);
};