Add a range based remove_if overload

This commit is contained in:
Maxime Coste 2020-05-29 11:59:03 +10:00
parent 109abbeed4
commit 94f33bb638
4 changed files with 21 additions and 16 deletions

View File

@ -170,13 +170,13 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer)
client->context().forget_buffer(buffer); client->context().forget_buffer(buffer);
Vector<std::unique_ptr<Window>> removed_windows; Vector<std::unique_ptr<Window>> removed_windows;
m_free_windows.erase(std::remove_if(m_free_windows.begin(), m_free_windows.end(), m_free_windows.erase(remove_if(m_free_windows,
[&buffer, &removed_windows](WindowAndSelections& ws) { [&buffer, &removed_windows](WindowAndSelections& ws) {
if (&ws.window->buffer() != &buffer) if (&ws.window->buffer() != &buffer)
return false; return false;
removed_windows.push_back(std::move(ws.window)); removed_windows.push_back(std::move(ws.window));
return true; return true;
}), }),
m_free_windows.end()); m_free_windows.end());
for (auto&& removed_window : removed_windows) for (auto&& removed_window : removed_windows)

View File

@ -36,14 +36,12 @@ void HookManager::remove_hooks(const Regex& regex)
{ {
for (auto& list : m_hooks) for (auto& list : m_hooks)
{ {
list.erase(std::remove_if(list.begin(), list.end(), list.erase(remove_if(list, [this, &regex](std::unique_ptr<HookData>& h) {
[this, &regex](std::unique_ptr<HookData>& h) { if (not regex_match(h->group.begin(), h->group.end(), regex))
if (not regex_match(h->group.begin(), h->group.end(), regex)) return false;
return false; m_hooks_trash.push_back(std::move(h));
m_hooks_trash.push_back(std::move(h)); return true;
return true; }), list.end());
}),
list.end());
} }
} }

View File

@ -142,7 +142,7 @@ void LineRangeSet::update(ConstArrayView<LineModification> modifs)
} }
} }
}; };
erase(std::remove_if(begin(), end(), [](auto& r) { return r.begin >= r.end; }), end()); erase(remove_if(*this, [](auto& r) { return r.begin >= r.end; }), end());
} }
void LineRangeSet::add_range(LineRange range, FunctionRef<void (LineRange)> on_new_range) void LineRangeSet::add_range(LineRange range, FunctionRef<void (LineRange)> on_new_range)

View File

@ -428,6 +428,13 @@ bool any_of(Range&& range, T op)
return std::any_of(begin(range), end(range), op); return std::any_of(begin(range), end(range), op);
} }
template<typename Range, typename T>
auto remove_if(Range&& range, T op)
{
using std::begin; using std::end;
return std::remove_if(begin(range), end(range), op);
}
template<typename Range, typename U> template<typename Range, typename U>
void unordered_erase(Range&& vec, U&& value) void unordered_erase(Range&& vec, U&& value)
{ {