intrusive_list: Add pop_back(), pop_front(), front(), and back() member functions
This commit is contained in:
parent
86f803da04
commit
669ffb5f3a
1 changed files with 54 additions and 0 deletions
|
@ -87,6 +87,24 @@ public:
|
|||
insert(end(), node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erases the node at the front of the list.
|
||||
* @note Must not be called on an empty list.
|
||||
*/
|
||||
void pop_front() {
|
||||
DEBUG_ASSERT(!empty());
|
||||
erase(begin());
|
||||
}
|
||||
|
||||
/**
|
||||
* Erases the node at the back of the list.
|
||||
* @note Must not be called on an empty list.
|
||||
*/
|
||||
void pop_back() {
|
||||
DEBUG_ASSERT(!empty());
|
||||
erase(--end());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes node from list
|
||||
* @param node Node to remove from list.
|
||||
|
@ -103,6 +121,42 @@ public:
|
|||
return root->next == root.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a reference to the node at the front of the list.
|
||||
* @note Must not be called on an empty list.
|
||||
*/
|
||||
reference front() {
|
||||
DEBUG_ASSERT(!empty());
|
||||
return *begin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a constant reference to the node at the front of the list.
|
||||
* @note Must not be called on an empty list.
|
||||
*/
|
||||
const_reference front() const {
|
||||
DEBUG_ASSERT(!empty());
|
||||
return *begin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a reference to the node at the back of the list.
|
||||
* @note Must not be called on an empty list.
|
||||
*/
|
||||
reference back() {
|
||||
DEBUG_ASSERT(!empty());
|
||||
return *--end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a constant reference to the node at the back of the list.
|
||||
* @note Must not be called on an empty list.
|
||||
*/
|
||||
const_reference back() const {
|
||||
DEBUG_ASSERT(!empty());
|
||||
return *--end();
|
||||
}
|
||||
|
||||
// Iterator interface
|
||||
iterator begin() { return iterator(root.get(), root->next); }
|
||||
const_iterator begin() const { return const_iterator(root.get(), root->next); }
|
||||
|
|
Loading…
Reference in a new issue