diff --git a/src/common/intrusive_list.h b/src/common/intrusive_list.h index 9308c255..1b24bb05 100644 --- a/src/common/intrusive_list.h +++ b/src/common/intrusive_list.h @@ -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); }