list< T > Class Template Reference

Linked list class. More...

#include <edelib/List.h>

List of all members.

Public Member Functions

 list ()
 ~list ()
void clear (void)
iterator insert (iterator it, const T &val)
iterator erase (iterator it)
void push_back (const T &val)
void push_front (const T &val)
iterator begin (void)
const_iterator begin (void) const
iterator end (void)
const_iterator end (void) const
T & front (void)
const T & front (void) const
T & back (void)
const T & back (void) const
size_type size (void) const
bool empty (void) const
bool operator== (list< T > &other)
bool operator!= (list< T > &other)
void sort (SortCmp *cmp=default_sort_cmp)

Detailed Description

template<typename T>
class edelib::list< T >

Linked list class.

This implementation is very similar to std::list, providing subset of the same methods with the same behaviours. On other hand, it does not try to implement all methods from std::list, since main goal is to keep it small and simple, which will as result generate much smaller code.

Also, size() method differs from std::list; some implementations run it in linear time, but some in constant time. This implementation returns size() result always in constant time.

Using list is the same as for std::list; all traversal is done via iterators. Here is sample:

   list<int> ls;
   ls.push_back(34);
   ls.push_back(4);
   ls.push_front(34);
   list<int>::iterator it = ls.begin();

   while(it != ls.end()) {
     printf("%i\n", (*it));
     ++it;
   }

Note that working with list iterators, great care must be taken where and when to retrieve iterators for start and end of the list. For example, this code is invalid:

   list<int> ls;

   // BAD, pointer to first element will be changed if list is empty
   list<int>::iterator it = ls.begin();
   ls.push_back(34);

   // or...
   list<int>::iterator it = ls.begin();
   // push_front() will invalidate previously retrieved iterator
   ls.push_front(34);

   // or...
   ls.push_front(34);
   list<int>::iterator it = ls.begin();
   // insert at the start invalidated begin()
   ls.insert(it, 33);

Correct way is retrieve iterator just before iterator will be used, like:

   list<int> ls;
   ls.push_back(34);
   ls.push_back(4);
   ls.push_front(4);
   list<int>::iterator it = ls.begin();
   // rest...

This issue is not related to this list implementation only; libstdc++ list will return garbage in above cases (but in some will crash); this implementation will always crash when above cases occurs, so be carefull :-P.


Constructor & Destructor Documentation

list (  )  [inline]

Creates an empty list

~list (  )  [inline]

Clears data


Member Function Documentation

const T& back ( void   )  const [inline]

Return const reference to last element in the list.

T& back ( void   )  [inline]

Return reference to last element in the list.

const_iterator begin ( void   )  const [inline]

Return const iterator pointing to the start of the list.

iterator begin ( void   )  [inline]

Return iterator pointing to the start of the list.

Referenced by list< IconLoaderItem * >::operator==().

void clear ( void   )  [inline]

Clear all data

bool empty ( void   )  const [inline]

Return true if list is empty; otherwise false.

const_iterator end ( void   )  const [inline]

Return const iterator pointing after the end of the list. Do not dereference that iterator requesting value of latest element.

iterator end ( void   )  [inline]

Return iterator pointing after the end of the list. Do not dereference that iterator requesting value of latest element.

iterator erase ( iterator  it  )  [inline]

Remove element given at iterator position.

Returns:
iterator pointing to the next element
Parameters:
it is element to be removed
const T& front ( void   )  const [inline]

Return const reference to first element in the list.

T& front ( void   )  [inline]

Return reference to first element in the list.

iterator insert ( iterator  it,
const T &  val 
) [inline]

Inserts given value at position before position poiniting by given iterator.

Returns:
iterator pointing to inserted element
Parameters:
it is location before to be inserted
val is value to insert
bool operator!= ( list< T > &  other  )  [inline]

Check if two list are not equal

bool operator== ( list< T > &  other  )  [inline]

Check if two list are equal

void push_back ( const T &  val  )  [inline]

Adds new value to the end of the list.

Parameters:
val is value to be added
void push_front ( const T &  val  )  [inline]

Adds new value to the beginning of the list.

Parameters:
val is value to be added
size_type size ( void   )  const [inline]

Return size of list.

Referenced by list< IconLoaderItem * >::operator==().

void sort ( SortCmp *  cmp = default_sort_cmp  )  [inline]

Sorts list. If cmp function is given (in form bool cmp(const T& v1, const T& v2), elements will be compared with it.


The documentation for this class was generated from the following file:

Generated on 7 May 2013 for edelib by  doxygen 1.6.1