Reactor: Fix remove_if brokenness
Spotted by Chris Forbes:
* `std::remove_if` wasn't introduced in C++20, it's been there since 98. I just can't read docs.
* Also fix the lack of `list.erase()`.
Bug: None. drive-by-code-reviewing-fixes.
Change-Id: I456d540ba973640747d6e4cb23faec65a4a9c83d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43348
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Reactor/Reactor.cpp b/src/Reactor/Reactor.cpp
index abe4882..dff1a29 100644
--- a/src/Reactor/Reactor.cpp
+++ b/src/Reactor/Reactor.cpp
@@ -16,6 +16,7 @@
#include "Debug.hpp"
#include "Print.hpp"
+#include <algorithm>
#include <cmath>
// Define REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION to non-zero to ensure all
@@ -24,28 +25,6 @@
# define REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION 0
#endif
-namespace {
-
-// Introduced in C++20.
-template<class ForwardIterator, class UnaryPredicate>
-ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
- UnaryPredicate pred)
-{
- ForwardIterator result = first;
- while(first != last)
- {
- if(!pred(*first))
- {
- *result = std::move(*first);
- ++result;
- }
- ++first;
- }
- return result;
-}
-
-} // anonymous namespace
-
namespace rr {
const Config::Edit Config::Edit::None = {};
@@ -71,7 +50,10 @@
list.push_back(edit.second);
break;
case ListEdit::Remove:
- ::remove_if(list.begin(), list.end(), [&](T item) { return item == edit.second; });
+ list.erase(std::remove_if(list.begin(), list.end(), [&](T item) {
+ return item == edit.second;
+ }),
+ list.end());
break;
case ListEdit::Clear:
list.clear();