From d8ea57169cf9e4d2d6979e19902e283385a49d71 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 12 Aug 2024 13:09:03 -0400 Subject: 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 --- gdb/unittests/intrusive_list-selftests.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'gdb/unittests') diff --git a/gdb/unittests/intrusive_list-selftests.c b/gdb/unittests/intrusive_list-selftests.c index b17ce92..0c09a64 100644 --- a/gdb/unittests/intrusive_list-selftests.c +++ b/gdb/unittests/intrusive_list-selftests.c @@ -446,15 +446,18 @@ struct intrusive_list_test ListType list; - list.insert (list.begin (), a); + auto a_it = list.insert (list.begin (), a); + SELF_CHECK (&*a_it == &a); expected = {&a}; verify_items (list, expected); - list.insert (list.begin (), b); + auto b_it = list.insert (list.begin (), b); + SELF_CHECK (&*b_it == &b); expected = {&b, &a}; verify_items (list, expected); - list.insert (list.begin (), c); + auto c_it = list.insert (list.begin (), c); + SELF_CHECK (&*c_it == &c); expected = {&c, &b, &a}; verify_items (list, expected); } @@ -465,15 +468,18 @@ struct intrusive_list_test ListType list; - list.insert (list.end (), a); + auto a_it = list.insert (list.end (), a); + SELF_CHECK (&*a_it == &a); expected = {&a}; verify_items (list, expected); - list.insert (list.end (), b); + auto b_it = list.insert (list.end (), b); + SELF_CHECK (&*b_it == &b); expected = {&a, &b}; verify_items (list, expected); - list.insert (list.end (), c); + auto c_it = list.insert (list.end (), c); + SELF_CHECK (&*c_it == &c); expected = {&a, &b, &c}; verify_items (list, expected); } @@ -486,7 +492,8 @@ struct intrusive_list_test list.push_back (a); list.push_back (b); - list.insert (list.iterator_to (b), c); + auto c_it = list.insert (list.iterator_to (b), c); + SELF_CHECK (&*c_it == &c); expected = {&a, &c, &b}; verify_items (list, expected); } @@ -496,7 +503,8 @@ struct intrusive_list_test item_type a ("a"); ListType list; - list.insert (list.end (), a); + auto a_it = list.insert (list.end (), a); + SELF_CHECK (&*a_it == &a); expected = {&a}; verify_items (list, expected); } -- cgit v1.1