|
| | List () |
| | Construct an empty list.
|
| |
| iterator | begin () |
| | Return an iterator for the first element in the list.
|
| |
| const_iterator | begin () const |
| |
| iterator | end () |
| | Return an iterator for the end of the list.
|
| |
| const_iterator | end () const |
| |
| bool | empty () const |
| | Return true iff size() == 0.
|
| |
| size_type | size () const |
| | Return the number of elements in the list.
|
| |
| pointer | front () |
| | Return the first element in the list.
|
| |
| const_pointer | front () const |
| |
| pointer | back () |
| | Return the last element in the list.
|
| |
| const_pointer | back () const |
| |
| void | push_front (pointer x) |
| | Insert a new element at the beginning of the list.
|
| |
| void | push_back (pointer x) |
| | Insert a new element at the end of the list.
|
| |
| void | pop_front () |
| | Remove the element at the beginning of the list.
|
| |
| void | pop_back () |
| | Remove the element at the end of the list.
|
| |
| void | insert (pointer pos, pointer x) |
| | Insert an element before pos.
|
| |
| iterator | insert (iterator it, pointer x) |
| | Insert an element before it.
|
| |
| template<typename InputIterator > |
| void | insert (iterator it, InputIterator first, InputIterator last) |
| | Insert the elements in [first, last) before it.
|
| |
| void | erase (pointer x) |
| | Remove x from the list.
|
| |
| iterator | erase (iterator it) |
| | Remove the element pointed to by it from the list.
|
| |
| iterator | erase (iterator first, iterator last) |
| | Remove the elements in [first, last) from the list.
|
| |
| void | clear () |
| | Remove all elements from the list.
|
| |
| void | __clear () |
| | Remove all elements from the list.
|
| |
| void | swap (List< T, member > &x) |
| | Exchange list contents with list x.
|
| |
| bool | isolated (const_pointer x) |
| | Check if x is isolated.
|
| |
| bool | contains (const_pointer x) const |
| | Check if x is a member of this list.
|
| |
template<typename T,
List_member< T > T::* member>
class List< T, member >
Doubly-linked list template.
The List template, and its helper template List_member, implement a generic doubly-linked list. The list is intrusive in that the container does not manage space for its contents. The user provides space for contained elements, and must delete elements when they are no longer needed. (This is unlike Vector or HashTable, which manage space for their contents.) The main advantage of intrusive containers is that a single element can be on multiple lists.
Here's an example linked list of integers built using List and List_member.
struct intlist_node {
int value;
intlist_node(int v)
: value(v) {
}
};
void make_intlist(intlist &l,
int begin,
int end,
int step) {
}
void print_intlist(const intlist &l) {
size_t n = 0;
for (intlist::const_iterator it = l.begin(); it != l.end(); ++it, ++n)
click_chatter("#%ld: %d\n", (long) n, it->value);
}
void trash_intlist(intlist &l) {
while (!l.empty()) {
intlist_node *n = l.front();
l.pop_front();
delete n;
}
}
template <typename T>
void remove_every_other(T &list) {
typename T::iterator it = list.begin();
while (it != l.end()) {
++it;
if (it != l.end())
it = list.erase(it);
}
}
Member of classes to be placed on a List.
Definition list.hh:102
Doubly-linked list template.
Definition list.hh:139
iterator end()
Return an iterator for the end of the list.
Definition list.hh:163
void push_back(pointer x)
Insert a new element at the end of the list.
Definition list.hh:226
iterator begin()
Return an iterator for the first element in the list.
Definition list.hh:154
Click's doubly-linked list container template.