Tuples¶
#include "tuple.tcc"
Tuples¶
Tuples can be used to group objects of different types. A Tuple is recursively defined as being either:
Empty.
A pair (
head
,tail
), wherehead
is of an arbitrary type andtail
is an other Tuple.
Initialisation of a Tuple can be done with a brace-initializer-list as follows.
Tuple<int, char> t {10, 'c'};
Element retrieval and assignment is described below in the Helper functions section.
Note that a Tuple, like any higher order data structure, should be passed by reference.
Class definitions¶
Helper functions¶
Elements of a Tuple can be retrieved in two ways, either via the head
and
tail
member variables, or using with the get<>()
helper function.
int i = t.head;
char c = t.tail.head;
int j = get<0>(t);
char d = get<1>(t)';
Likewise, assignment of an element can be done via its member variables or with
the get<>()
helper function.
t.head = 11;
t.tail.head = 'd';
get<0>(t) = 11;
get<1>(t) = 'd';
There are additional helper functions available for the creation of Tuples.
The function makeTuple()
can be used to create a temporary Tuple to be used in a
function call.
function(makeTuple('a', 'b', 10));