edelib
2.1.0
|
Linked list class. More...
#include <edelib/List.h>
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) |
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:
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:
Correct way is retrieve iterator just before iterator will be used, like:
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.
|
inline |
Creates an empty list
|
inline |
Clears data
|
inline |
Return reference to last element in the list.
|
inline |
Return const reference to last element in the list.
|
inline |
Return iterator pointing to the start of the list.
Referenced by list< edelib::EdbusData >::operator==().
|
inline |
Return const iterator pointing to the start of the list.
|
inline |
Clear all data
|
inline |
Return true if list is empty; otherwise false.
|
inline |
Return iterator pointing after the end of the list. Do not dereference that iterator requesting value of latest element.
|
inline |
Return const iterator pointing after the end of the list. Do not dereference that iterator requesting value of latest element.
|
inline |
Remove element given at iterator position.
it | is element to be removed |
|
inline |
Return reference to first element in the list.
|
inline |
Return const reference to first element in the list.
|
inline |
Inserts given value at position before position poiniting by given iterator.
it | is location before to be inserted |
val | is value to insert |
|
inline |
Check if two list are not equal
|
inline |
Check if two list are equal
|
inline |
Adds new value to the end of the list.
val | is value to be added |
|
inline |
Adds new value to the beginning of the list.
val | is value to be added |
|
inline |
Return size of list.
Referenced by list< edelib::EdbusData >::operator==().
|
inline |
Sorts list. If cmp function is given (in form bool cmp(const T& v1, const T& v2), elements will be compared with it.