[Scummvm-git-logs] scummvm master -> 08010fa1858f6e9632e4670378d199d2a3cc101f

bluegr noreply at scummvm.org
Tue Jul 30 10:29:22 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
08010fa185 COMMON: Return an iterator for List::insert


Commit: 08010fa1858f6e9632e4670378d199d2a3cc101f
    https://github.com/scummvm/scummvm/commit/08010fa1858f6e9632e4670378d199d2a3cc101f
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2024-07-30T13:29:18+03:00

Commit Message:
COMMON: Return an iterator for List::insert

Changed paths:
    common/list.h
    common/std/list.h
    engines/ultima/shared/std/containers.h
    engines/ultima/ultima8/world/current_map.cpp
    test/common/list.h


diff --git a/common/list.h b/common/list.h
index 3a1b29bb42e..020e5e9085b 100644
--- a/common/list.h
+++ b/common/list.h
@@ -74,8 +74,9 @@ public:
 	/**
 	 * Insert an @p element before @p pos.
 	 */
-	void insert(iterator pos, const t_T &element) {
+	iterator insert(iterator pos, const t_T &element) {
 		insert(pos._node, element);
+		return --pos;
 	}
 
 	/**
diff --git a/common/std/list.h b/common/std/list.h
index 313ad5048f4..1015abc5cc0 100644
--- a/common/std/list.h
+++ b/common/std/list.h
@@ -64,12 +64,6 @@ public:
 	}
 };
 public:
-	typename Common::List<T>::iterator insert(typename Common::List<T>::iterator pos,
-			const T &element) {
-		Common::List<T>::insert(pos, element);
-		return --pos;
-	}
-
 	reverse_iterator rbegin() {
 		return reverse_iterator(Common::List<T>::reverse_begin());
 	}
diff --git a/engines/ultima/shared/std/containers.h b/engines/ultima/shared/std/containers.h
index 7250a473bcf..5a166ddf72e 100644
--- a/engines/ultima/shared/std/containers.h
+++ b/engines/ultima/shared/std/containers.h
@@ -217,12 +217,6 @@ public:
 		bool operator!=(const reverse_iterator &rhs) { return _it != rhs._it; }
 	};
 public:
-	typename Common::List<T>::iterator insert(typename Common::List<T>::iterator pos,
-			const T &element) {
-		Common::List<T>::insert(pos, element);
-		return pos;
-	}
-
 	reverse_iterator rbegin() {
 		return reverse_iterator(Common::List<T>::reverse_begin());
 	}
diff --git a/engines/ultima/ultima8/world/current_map.cpp b/engines/ultima/ultima8/world/current_map.cpp
index 5b5549a8958..7eb08a42db5 100644
--- a/engines/ultima/ultima8/world/current_map.cpp
+++ b/engines/ultima/ultima8/world/current_map.cpp
@@ -1200,7 +1200,7 @@ bool CurrentMap::sweepTest(const Point3 &start, const Point3 &end,
 					}
 
 					// Now add it
-					sw_it = hit->insert(sw_it, SweepItem(other_item->getObjId(), first, last, touch, touch_floor, blocking, dirs));
+					hit->insert(sw_it, SweepItem(other_item->getObjId(), first, last, touch, touch_floor, blocking, dirs));
 
 					//debugC(kDebugCollision, "Hit item %u (%d, %d, %d) at first: %d, last: %d",
 					//	   other_item->getObjId(), other[0], other[1], other[2], first, last);
diff --git a/test/common/list.h b/test/common/list.h
index 232aa82bd85..cc0fcad02fd 100644
--- a/test/common/list.h
+++ b/test/common/list.h
@@ -100,9 +100,15 @@ class ListTestSuite : public CxxTest::TestSuite
 		++iter;
 		++iter;
 
-		// Now insert some values here
+		// Insert a value before the final one
 		container.insert(iter, 42);
-		container.insert(iter, 43);
+
+		// Insert another value before the final one and check the return value
+		iter = container.insert(iter, 43);
+		TS_ASSERT_EQUALS(*iter, 43);
+
+		// Insert a value before the previously inserted one
+		container.insert(iter, 44);
 
 		// Verify contents are correct
 		iter = container.begin();
@@ -119,6 +125,10 @@ class ListTestSuite : public CxxTest::TestSuite
 		++iter;
 		TS_ASSERT_DIFFERS(iter, container.end());
 
+		TS_ASSERT_EQUALS(*iter, 44);
+		++iter;
+		TS_ASSERT_DIFFERS(iter, container.end());
+
 		TS_ASSERT_EQUALS(*iter, 43);
 		++iter;
 		TS_ASSERT_DIFFERS(iter, container.end());




More information about the Scummvm-git-logs mailing list