diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2024-08-12 13:09:03 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2024-09-13 07:38:56 -0400 |
commit | d8ea57169cf9e4d2d6979e19902e283385a49d71 (patch) | |
tree | d8f05d0c97db2104fc54b6f32e4f6ab94426cdb3 /gdbsupport | |
parent | 96917d0541db09977afaba3e6f8a53bfb31bcf45 (diff) | |
download | gdb-d8ea57169cf9e4d2d6979e19902e283385a49d71.zip gdb-d8ea57169cf9e4d2d6979e19902e283385a49d71.tar.gz gdb-d8ea57169cf9e4d2d6979e19902e283385a49d71.tar.bz2 |
gdbsupport/intrusive-list: make insert return an iterator
Make the insert method return an iterator to the inserted element. This
mimics what boost does [1] and what the standard library insert methods
generally do [2].
[1] https://www.boost.org/doc/libs/1_79_0/doc/html/boost/intrusive/list.html#idm33771-bb
[2] https://en.cppreference.com/w/cpp/container/vector/insert
Change-Id: I59082883492c60ee95e8bb29a18c9376283dd660
Reviewed-by: Keith Seitz <keiths@redhat.com>
Diffstat (limited to 'gdbsupport')
-rw-r--r-- | gdbsupport/intrusive_list.h | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/gdbsupport/intrusive_list.h b/gdbsupport/intrusive_list.h index 3c9245f..bfa06fc 100644 --- a/gdbsupport/intrusive_list.h +++ b/gdbsupport/intrusive_list.h @@ -334,8 +334,10 @@ public: this->push_back_non_empty (elem); } - /* Inserts ELEM before POS. */ - void insert (const_iterator pos, reference elem) noexcept + /* Inserts ELEM before POS. + + Returns an iterator to the inserted element. */ + iterator insert (const_iterator pos, reference elem) noexcept { if (this->empty ()) return this->push_empty (elem); @@ -359,6 +361,8 @@ public: prev_node->next = &elem; elem_node->next = pos_elem; pos_node->prev = &elem; + + return this->iterator_to (elem); } /* Move elements from LIST at the end of the current list. */ @@ -402,7 +406,7 @@ public: private: /* Push ELEM in the list, knowing the list is empty. */ - void push_empty (reference elem) noexcept + iterator push_empty (reference elem) noexcept { gdb_assert (this->empty ()); @@ -415,10 +419,12 @@ private: m_back = &elem; elem_node->prev = nullptr; elem_node->next = nullptr; + + return this->iterator_to (elem); } /* Push ELEM at the front of the list, knowing the list is not empty. */ - void push_front_non_empty (reference elem) noexcept + iterator push_front_non_empty (reference elem) noexcept { gdb_assert (!this->empty ()); @@ -432,10 +438,12 @@ private: front_node->prev = &elem; elem_node->prev = nullptr; m_front = &elem; + + return this->iterator_to (elem); } /* Push ELEM at the back of the list, knowing the list is not empty. */ - void push_back_non_empty (reference elem) noexcept + iterator push_back_non_empty (reference elem) noexcept { gdb_assert (!this->empty ()); @@ -449,6 +457,8 @@ private: back_node->next = &elem; elem_node->next = nullptr; m_back = &elem; + + return this->iterator_to (elem); } void erase_element (reference elem) noexcept |