« Home » « Learn » « Download » « Github »

logo

Cello High Level C

Methods

copy

var copy(var self);

Make a copy of the object self.

Examples

Usage

var x = new(String, $S("Hello"));
var y = copy(x);
show(x); /* Hello */
show(y); /* Hello */
show($I(eq(x, y))); /* 1 */
show($I(x is y)); /* 0 */

Copy


Copyable

The Copy class can be used to override the behaviour of an object when a copy is made of it. By default the Copy class allocates a new empty object of the same type and uses the Assign class to set the contents. The copy is then registered with the Garbage Collector as if it had been constructed with new. This means when using manual memory management a copy must be deleted manually.

If the copy class is overridden then the implementer may manually have to register the object with the Garbage Collector if they wish for it to be tracked.

By convention copy follows the semantics of Assign, which typically means a deep copy should be made, and that an object will create a copy of all of the sub-objects it references or contains - although this could vary depending on the type's overridden behaviours.

Definition

struct Copy {
  var (*copy)(var);
};

Derivers

  • Array |     Sequential Container
  • Box |     Unique Pointer
  • Exception |     Exception Object
  • File |     Operating System File
  • Filter |     Filtered Iterable
  • Float |     Floating Point Object
  • Function |     Function Object
  • GC |     Garbage Collector
  • Int |     Integer Object
  • List |     Linked List
  • Map |     Apply Function to Iterable
  • Mutex |     Mutual Exclusion Lock
  • Process |     Operating System Process
  • Range |     Integer Sequence
  • Ref |     Shared Pointer
  • Slice |     Partial Iterable
  • String |     String Object
  • Table |     Hash table
  • Thread |     Concurrent Execution
  • Tree |     Balanced Binary Tree
  • Tuple |     Basic Collection
  • Zip |     Multiple Iterator

Implementers

  • Type |     Metadata Object

Back