next up previous contents index
Next: Code examples for the Up: The golden LEDA rules Previous: The golden LEDA rules   Contents   Index

The LEDA rules in detail

  1. (Definition with initialization by copying) Definition with initialization by copying is possible for every LEDA type. It initializes the defined variable with a copy of the argument of the definition. The next rule states precisely what a copy of a value is.

  2. (Copy of a value) Assignment operator and copy constructor of LEDA types create copies of values. This rule defines recursively what is meant by the notion ``copy of a value''.

    1. A copy of a value of a primitive type (built-in type, pointer type, item type) is a bitwise copy of this value.

    2. A value x of a simple-structured type is a set or a sequence of values, respectively.

      A copy of x is a componentwise copy of all constituent values of this set or this sequence, respectively.

    3. A value x of an item-based, structured type is a structured collection of values.

      A copy of x is a collection of new values, each one of which is the copy of a value of x, the original . The combinatorical structure imposed to the new values is isomorphic to the structure of x, the original.

  3. (Equality and identity) This rule defines when two objects x and y are considered as equal and identical, respectively.

    1. For objects x and y of a dependent item type, the equality predicate x==y means equality between the values of these objects.

    2. For objects x and y of an independent item type T, the equality predicate x==y is defined individually for each such item type. In the majority of cases it means equality between the values of x and y, but this is not guaranteed for every type.

      Provided that the identity predicate

      bool identical(const T&, const T&);
      

      is defined on type T, it means equality between the values of these objects.

    3. For objects x and y of a structured type the equality predicate x==y means equality between the values of these objects.

  4. (Illegal access via an item) It is illegal to access a container which has been destroyed via an item, or to access a container via the item nil.

  5. (Initialization of attributes of an independent item type) The attributes of an independent item type are always defined. In particular, a definition with default initialization initializes all attributes. Such a type may specify the initial values, but it need not.

  6. (Specification of the structure to be traversed in forall-macros)

    The argument in a forall-macro which specifies the structure to be traversed should not be a function call which returns this structure, but rather an object by itself which represents this structure.

  7. (Modification of objects of an item-based container type while iterating over them)

    An iteration over an object x of an item-based container type must not add new elements to x. It may delete the element which the iterator item points to, but no other element. The values of the elements may be modified without any restrictions.

  8. (Requirements for type parameters)

    Every type parameter T must implement the following functions:

    a default constructor T::T()
    a copy constructor T::T(const T&)
    an assigment operator T& T::operator = (const T&)
    an input operator istream& operator >> (istream&, T&)
    an output operator ostream& operator << (ostream&, const T&)

  9. (Requirements for linearly ordered types)

    In addition to the Requirements for type parameters a linearly ordered type must implement

    a compare function int compare(const T&, const T&)

    Here, for the function compare() the following must hold:

    1. It must be put in the namespace leda.

    2. It must realize a linear order on T.

    3. If y is the copy of a value x of type T, then compare(x,y) == 0 must hold.

  10. (Requirements for hashed types) In addition to the Requirements for type parameters a hashed type must implement

    a hash function int Hash(const T&)
    an equality operator bool operator == (const T&, const T&)

    Here, for the function Hash() the following must hold:

    1. It must be put in the namespace leda.

    2. For all objects x and y of type T: If x == y holds, then so does Hash(x) == Hash(y).

    For the equality operator operator==() the following must hold:

    1. It defines an equivalence relation on T.

    2. If y is a copy of a value x of type T, then x == y must hold.

  11. (Requests for numerical types) In addition to the Requirements for type parameters a numerical type must offer the arithmetical operators operator+(), operator-(), and operator*(), as well as the comparison operators operator<(), operator<=(), operator>(), operator>=(), operator==(), and operator!=().


next up previous contents index
Next: Code examples for the Up: The golden LEDA rules Previous: The golden LEDA rules   Contents   Index