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);
Vector<std::unique_ptr<Window>> removed_windows;
m_free_windows.erase(std::remove_if(m_free_windows.begin(), m_free_windows.end(),
[&buffer, &removed_windows](WindowAndSelections& ws) {
if (&ws.window->buffer() != &buffer)
return false;
removed_windows.push_back(std::move(ws.window));
return true;
}),
m_free_windows.erase(remove_if(m_free_windows,
[&buffer, &removed_windows](WindowAndSelections& ws) {
if (&ws.window->buffer() != &buffer)
return false;
removed_windows.push_back(std::move(ws.window));
return true;
}),
m_free_windows.end());
for (auto&& removed_window : removed_windows)

View File

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

View File

@ -428,6 +428,13 @@ bool any_of(Range&& range, T 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>
void unordered_erase(Range&& vec, U&& value)
{