Commit 983761cc by Ben Clayton

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: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent 68d9ad83
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "Debug.hpp" #include "Debug.hpp"
#include "Print.hpp" #include "Print.hpp"
#include <algorithm>
#include <cmath> #include <cmath>
// Define REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION to non-zero to ensure all // Define REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION to non-zero to ensure all
...@@ -24,28 +25,6 @@ ...@@ -24,28 +25,6 @@
# define REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION 0 # define REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION 0
#endif #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 { namespace rr {
const Config::Edit Config::Edit::None = {}; const Config::Edit Config::Edit::None = {};
...@@ -71,7 +50,10 @@ void rr::Config::Edit::apply(const std::vector<std::pair<ListEdit, T>> &edits, s ...@@ -71,7 +50,10 @@ void rr::Config::Edit::apply(const std::vector<std::pair<ListEdit, T>> &edits, s
list.push_back(edit.second); list.push_back(edit.second);
break; break;
case ListEdit::Remove: 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; break;
case ListEdit::Clear: case ListEdit::Clear:
list.clear(); list.clear();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment