31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

(c) If y is the copy of a value x of type T, then compare(x,y) == 0 must hold.<br />

10. (Requirements for hashed types) In addition to the Requirements for type parameters<br />

a hashed type must implement<br />

a hash function<br />

an equality operator<br />

int Hash(const T&)<br />

bool operator == (const T&, const T&)<br />

Here, for the function Hash() the following must hold:<br />

(a) It must be put in the namespace leda.<br />

(b) For all objects x and y of type T: If x == y holds, then so does<br />

Hash(x) == Hash(y).<br />

For the equality operator operator==() the following must hold:<br />

(a) It defines an equivalence relation on T.<br />

(b) If y is a copy of a value x of type T, then x == y must hold.<br />

11. (Requests for numerical types) In addition to the Requirements for type parameters<br />

a numerical type must offer the arithmetical operators operator+(),<br />

operator-(), and operator*(), as well as the comparison operators operator=(), operator==(), and operator!=().<br />

B.2 Code examples for the <strong>LEDA</strong> rules<br />

1. string s("Jumping Jack Flash");<br />

string t(s); // definition with initialization by copying<br />

string u = s; // definition with initialization by copying<br />

stack S;<br />

// ... fill S with some elements<br />

stack T(S); // definition with initialization by copying<br />

2. (a) list_item it1, it2;<br />

// ...<br />

it2 = it1; // it2 now references the same container as it1<br />

(b) array A, B;<br />

// ...fill A with some elements...<br />

B = A;<br />

Now B contains the same number of integers as A, in the same order, with the<br />

same values.<br />

However, A and B do not contain the same objects:<br />

int* p = A[0];<br />

int* q = B[0];<br />

p == q; // false

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!