[Scummvm-git-logs] scummvm master -> 5a069277f9dc013cc4e9a0eca18c279916b46475

bluegr noreply at scummvm.org
Mon Aug 22 17:28:58 UTC 2022


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:
5a069277f9 COMMON: Add a range-based version of Common::Array::erase()


Commit: 5a069277f9dc013cc4e9a0eca18c279916b46475
    https://github.com/scummvm/scummvm/commit/5a069277f9dc013cc4e9a0eca18c279916b46475
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2022-08-22T20:28:53+03:00

Commit Message:
COMMON: Add a range-based version of Common::Array::erase()

Changed paths:
    common/array.h
    engines/ultima/shared/std/containers.h


diff --git a/common/array.h b/common/array.h
index ced7a08096b..461f2ffc862 100644
--- a/common/array.h
+++ b/common/array.h
@@ -291,6 +291,20 @@ public:
 		return pos;
 	}
 
+	/** Erase the elements from @p first to @p last and return an iterator pointing to the next element in the array. */
+	iterator erase(iterator first, iterator last) {
+		copy(last, _storage + _size, first);
+
+		int count = (last - first);
+		_size -= count;
+
+		// We also need to destroy the objects beyond the new size
+		for (uint idx = _size; idx < (_size + count); ++idx)
+			_storage[idx].~T();
+
+		return first;
+	}
+
 	/** Check whether the array is empty. */
 	bool empty() const {
 		return (_size == 0);
diff --git a/engines/ultima/shared/std/containers.h b/engines/ultima/shared/std/containers.h
index 1d8016022df..89314d10960 100644
--- a/engines/ultima/shared/std/containers.h
+++ b/engines/ultima/shared/std/containers.h
@@ -98,24 +98,6 @@ public:
 		resize(newSize, elem);
 	}
 
-	typename Common::Array<T>::iterator erase(typename Common::Array<T>::iterator pos) {
-		return Common::Array<T>::erase(pos);
-	}
-
-	typename Common::Array<T>::iterator erase(typename Common::Array<T>::iterator first,
-			typename Common::Array<T>::iterator last) {
-		Common::copy(last, this->_storage + this->_size, first);
-
-		int count = (last - first);
-		this->_size -= count;
-
-		// We also need to destroy the objects beyond the new size
-		for (uint idx = this->_size; idx < (this->_size + count); ++idx)
-			this->_storage[idx].~T();
-
-		return first;
-	}
-
 	void swap(vector &arr) {
 		SWAP(this->_capacity, arr._capacity);
 		SWAP(this->_size, arr._size);




More information about the Scummvm-git-logs mailing list