next up previous contents
Next: Number Types and Linear Up: Simple Data Types and Previous: Three Tuples (three_tuple)

   
Four Tuples (four_tuple)

Definition

An instance p of type four_tuple<A,B,C,D> is a four-tuple (a,b,c,d) of variables of types A, B, C, and D, respectively.

Related types are two_tuple, three_tuple, and four_tuple.

Creation

four_tuple<A,B,C,D> p; creates an instance p of type four_tuple<A,B,C,D>. All components are initialized to their default value.

four_tuple<A,B,C,D>

p(A u, B v, C w, D x); creates an instance p of type four_tuple<A,B,C,D> and initializes it with the value (u,v,w,x).

   

Operations

A& p.first() returns the A-component of p. If p is a const-object the return type is A.
B& p.second() returns the B-component of p. If p is a const-object the return type is B.
C& p.third() returns the C-component of p. If p is a const-object the return type is C.
D& p.fourth() returns the D-component of p. If p is a const-object the return type is D.
bool p == q equality test for four_tuples. Each of the component types must have an equality operator.
int compare(four_tuple<A,B,C,D> p, four_tuple<A,B,C,D> q)
    lexicographic ordering for four_tuples. Each of the component types must have a compare function.
int Hash(four_tuple<A,B,C,D> p)
    hash function for four_tuples. Each of the component types must have a Hash function.

Implementation

The obvious implementation is used.

Example

We customize four_tuples and define a h_array for them.

#define prio() first()
#define inf()  second()
#define pq_item() third()
#define part_item() fourth()
typedef four_tuple<int,int,int,int> my_qu;

my_qu q; 
my_qu q1(2,2,0,0);
q.prio() = 5;

h_array<my_qu,int> M;
M[my_qu(2,2,nil,nil)] = 5;


next up previous contents
Next: Number Types and Linear Up: Simple Data Types and Previous: Three Tuples (three_tuple)
LEDA research project
1998-10-02