Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
list< T > Class Template Reference

#include <elm/imm/list.h>

+ Inheritance diagram for list< T >:

Classes

class  Collector
 

Public Member Functions

 list (void)
 
 list (const list< T > &l)
 
list< T > & operator= (list< T > l)
 
const T & hd (void) const
 
list< T > tl (void) const
 
const T & operator* (void) const
 
bool isEmpty (void) const
 
 operator bool (void) const
 
int length (void) const
 
bool contains (const T &v)
 
bool equals (list< T > l) const
 
bool operator== (list< T > l) const
 
bool operator!= (list< T > l) const
 
list< T > concat (list< T > l)
 
list< T > remove (const T &h)
 

Static Public Member Functions

static void add (Collector &coll)
 
static void remove (Collector &coll)
 
static list< T > cons (const T &h, list< T > t)
 

Static Public Attributes

static list< T > null
 

Detailed Description

template<class T>
class elm::imm::list< T >

Implementation of immutable and garbage collected list.

As C++ does not allow to implement easily and efficiently a garbage collector, the user of this class is responsible to provided its own collector using the function list<T>::add(object) with object inheriting from list<T>::Collector and implementing the member function list<T>::Collector::collect(). This function must call mark() for each list in use as in the example below:

list<int> first_list;
class MyCollector: public list<int>::Collector {
protected:
virtual void collect(void) {
mark(first_list);
for(int i = 0; i < lists.count(); i++)
mark(lists[i]);
}
};
int main(void) {
MyCollector coll;
// work with lists now
}
Parameters
TType of items in the list.

Constructor & Destructor Documentation

◆ list() [1/2]

list ( void  )
inline

Build an empty list.

◆ list() [2/2]

list ( const list< T > &  l)
inline

Member Function Documentation

◆ add()

static void add ( Collector coll)
inlinestatic

◆ concat()

list<T> concat ( list< T >  l)
inline

◆ cons()

list< T > cons ( const T &  h,
list< T >  t 
)
inlinestatic

Build a new list by prepending h to t.

Parameters
hItem to prepend.
tList to use as tail.
Returns
Built list.

Referenced by list< T >::concat(), elm::imm::cons(), and list< T >::remove().

◆ contains()

bool contains ( const T &  v)
inline

Test if v is in the list. The Equiv<T> is used to perform the test of equality. Therefore, a user can provide its own implementation of Equiv<T> to change the usual behavior of the equality tests.

Parameters
vItem to test.
Returns
True if v is in the list, false else.

◆ equals()

bool equals ( list< T >  l) const
inline

Test if the current list and l are equals.

Parameters
lList to compare.
Returns
True if both lists are equal, false else.

References list< T >::hd(), and list< T >::tl().

Referenced by list< T >::operator!=(), and list< T >::operator==().

◆ hd()

const T & hd ( void  ) const
inline

◆ isEmpty()

bool isEmpty ( void  ) const
inline

Test if the list is empty.

Returns
True if the list is empty, false else.

Referenced by list< T >::concat(), and list< T >::operator bool().

◆ length()

int length ( void  ) const
inline

Compute the length of the list.

Returns
List length.

◆ operator bool()

operator bool ( void  ) const
inline

References list< T >::isEmpty().

◆ operator!=()

bool operator!= ( list< T >  l) const
inline

References list< T >::equals().

◆ operator*()

const T& operator* ( void  ) const
inline

References list< T >::hd().

◆ operator=()

list<T>& operator= ( list< T >  l)
inline

◆ operator==()

bool operator== ( list< T >  l) const
inline

References list< T >::equals().

◆ remove() [1/2]

static void remove ( Collector coll)
inlinestatic

◆ remove() [2/2]

list< T > remove ( const T &  h)
inline

Build a new list without the first instance of h.

Parameters
hItem to remove.
Returns
List without first instance of h.

References list< T >::cons(), list< T >::hd(), and list< T >::tl().

◆ tl()

list< T > tl ( void  ) const
inline

Get the sub-list after the first item in the list.

Returns
Tail of the list.

Referenced by list< T >::concat(), sorted_list< T, K, C >::contains(), list< T >::equals(), elm::imm::operator<<(), and list< T >::remove().

Member Data Documentation

◆ null

list< T > null
static

The documentation for this class was generated from the following files:
elm::imm::list::list
list(void)
Definition: list.h:70
elm::imm::list::add
static void add(Collector &coll)
Definition: list.h:66
Vector