[Scummvm-git-logs] scummvm master -> b8f6af8dfe98b1146ff4f71def1c31b29489a345
sev-
noreply at scummvm.org
Thu Jun 1 14:32:14 UTC 2023
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
698bb261d1 COMMON: Add remove() to algorithm
4924a35540 TEST: Add more testcases for Common::remove()
b8f6af8dfe COMMON: Update documentation for Common::remove()
Commit: 698bb261d11a4a37b59d24aefc2e13ffb67a10a6
https://github.com/scummvm/scummvm/commit/698bb261d11a4a37b59d24aefc2e13ffb67a10a6
Author: hax0kartik (agarwala.kartik at gmail.com)
Date: 2023-06-01T16:32:03+02:00
Commit Message:
COMMON: Add remove() to algorithm
Changed paths:
common/algorithm.h
test/common/algorithm.h
diff --git a/common/algorithm.h b/common/algorithm.h
index 507acf32f71..a4a5eafff63 100644
--- a/common/algorithm.h
+++ b/common/algorithm.h
@@ -390,6 +390,25 @@ void replace(It begin, It end, const Dat &original, const Dat &replaced) {
}
}
+/**
+ * Removes all elements that are equal to value from the range [first, last).
+ * This function is the equivalent of std::remove.
+ */
+template<class It, class T>
+It remove(It first, It last, const T& val) {
+ first = find(first, last, val);
+ if (first != last) {
+ It i = first;
+ while (++i != last) {
+ if (!(*i == val)) {
+ *first = move(*i);
+ first++;
+ }
+ }
+ }
+ return first;
+}
+
/** @} */
} // End of namespace Common
diff --git a/test/common/algorithm.h b/test/common/algorithm.h
index 9a79e8e101f..50f26dbe835 100644
--- a/test/common/algorithm.h
+++ b/test/common/algorithm.h
@@ -4,6 +4,7 @@
#include "common/func.h"
#include "common/algorithm.h"
#include "common/list.h"
+#include "common/array.h"
#include "common/str.h"
class AlgorithmTestSuite : public CxxTest::TestSuite {
@@ -154,4 +155,13 @@ public:
TS_ASSERT_EQUALS(checkEqual(original.begin(), original.end(), expected.begin()), true);
}
+
+ void test_container_remove() {
+ Common::Array<int> original {1, 2, 3, 10, 4, 5};
+ Common::Array<int> expected {1, 2, 3, 4, 5};
+
+ Common::remove(original.begin(), original.end(), 10);
+
+ TS_ASSERT_EQUALS(checkEqual(expected.begin(), expected.end(), original.begin()), true);
+ }
};
Commit: 4924a355409d038f328402789a5cb7dfc01e37f5
https://github.com/scummvm/scummvm/commit/4924a355409d038f328402789a5cb7dfc01e37f5
Author: hax0kartik (agarwala.kartik at gmail.com)
Date: 2023-06-01T16:32:03+02:00
Commit Message:
TEST: Add more testcases for Common::remove()
Changed paths:
test/common/algorithm.h
diff --git a/test/common/algorithm.h b/test/common/algorithm.h
index 50f26dbe835..c2bdabacad3 100644
--- a/test/common/algorithm.h
+++ b/test/common/algorithm.h
@@ -157,11 +157,29 @@ public:
}
void test_container_remove() {
- Common::Array<int> original {1, 2, 3, 10, 4, 5};
- Common::Array<int> expected {1, 2, 3, 4, 5};
+ {
+ Common::Array<int> original {1, 2, 3, 10, 4, 5};
+ Common::Array<int> expected {1, 2, 3, 4, 5};
+
+ Common::Array<int>::iterator r = Common::remove(original.begin(), original.end(), 10);
+
+ TS_ASSERT_EQUALS(checkEqual(original.begin(), r, expected.begin()), true);
+ }
+ {
+ Common::Array<int> original {1, 2, 2, 3, 4, 4, 2, 1, 0};
+ Common::Array<int> expected {1, 3, 4, 4, 1, 0};
- Common::remove(original.begin(), original.end(), 10);
+ Common::Array<int>::iterator r = Common::remove(original.begin(), original.end(), 2);
- TS_ASSERT_EQUALS(checkEqual(expected.begin(), expected.end(), original.begin()), true);
+ TS_ASSERT_EQUALS(checkEqual(original.begin(), r, expected.begin()), true);
+ }
+ {
+ Common::Array<int> original {0, 1, 2, 3, 0, 3, 2, 1, 0};
+ Common::Array<int> expected {1, 2, 3, 3, 2, 1};
+
+ Common::Array<int>::iterator r = Common::remove(original.begin(), original.end(), 0);
+
+ TS_ASSERT_EQUALS(checkEqual(original.begin(), r, expected.begin()), true);
+ }
}
};
Commit: b8f6af8dfe98b1146ff4f71def1c31b29489a345
https://github.com/scummvm/scummvm/commit/b8f6af8dfe98b1146ff4f71def1c31b29489a345
Author: hax0kartik (agarwala.kartik at gmail.com)
Date: 2023-06-01T16:32:03+02:00
Commit Message:
COMMON: Update documentation for Common::remove()
Changed paths:
common/algorithm.h
diff --git a/common/algorithm.h b/common/algorithm.h
index a4a5eafff63..7b4fc188f14 100644
--- a/common/algorithm.h
+++ b/common/algorithm.h
@@ -393,6 +393,11 @@ void replace(It begin, It end, const Dat &original, const Dat &replaced) {
/**
* Removes all elements that are equal to value from the range [first, last).
* This function is the equivalent of std::remove.
+ *
+ * @param[in] first Iterator to the first position to be examined.
+ * @param[in] last Iterator to the last position.
+ * @param[in] val Value to be removed.
+ * @return An iterator to the new end of the range.
*/
template<class It, class T>
It remove(It first, It last, const T& val) {
More information about the Scummvm-git-logs
mailing list