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

logo

Cello High Level C

Methods

tuple

#define tuple(...)

Construct a Tuple object on the stack.

Examples

Usage

var x = tuple($I(100), $I(200), $S("Hello"));
show(x);
var y = tuple(Int, $I(10), $I(20));
var z = new_with(Array, y);
show(z);

foreach (item in x) {
  println("%$", item);
}

Tuple


Basic Collection

The Tuple type provides a basic way to create a simple collection of objects. Its main use is the fact that it can be constructed on the stack using the tuple macro. This makes it suitable for a number of purposes such as use in functions that take a variable number of arguments.

Tuples can also be constructed on the heap and stored in collections. This makes them also useful as a simple untyped list of objects.

Internally Tuples are just an array of pointers terminated with a pointer to the Cello Terminal object. This makes positional access fast, but many other operations slow including iteration and counting the number of elements. Due to this it is only recommended Tuples are used for small collections.

Because Tuples are terminated with the Cello Terminal object this can't naturally be included within them. This object should therefore only be returned from iteration functions.

Definition

struct Tuple {
  var* items;
};

Derives

Implements

  • Assignassign
  • Cmpcmp eq neq gt lt ge le
  • Concatappend concat
  • Docname brief description definition
  • Getget set mem rem key_type val_type
  • Hashhash hash_data
  • Iterforeach iter_init iter_next iter_type
  • Lenlen
  • Markmark
  • Newnew del construct destruct
  • Pushpush pop push_at pop_at
  • Resizeresize
  • Showshow look print scan
  • Sortsort sort_by

Back