summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2020-05-29 11:59:03 +1000
committerMaxime Coste <mawww@kakoune.org>2020-05-29 11:59:03 +1000
commit94f33bb63862357557ef533126a41d64b12f1c53 (patch)
tree4290036b7388a2b2a50972ec8ba0c9b25d9f9466 /src
parent109abbeed40c776fdc33bd5c9344b6865122ef6d (diff)
Add a range based remove_if overload
Diffstat (limited to 'src')
-rw-r--r--src/client_manager.cc14
-rw-r--r--src/hook_manager.cc14
-rw-r--r--src/line_modification.cc2
-rw-r--r--src/ranges.hh7
4 files changed, 21 insertions, 16 deletions
diff --git a/src/client_manager.cc b/src/client_manager.cc
index d1ac5bf3..f46d16ea 100644
--- a/src/client_manager.cc
+++ b/src/client_manager.cc
@@ -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)
diff --git a/src/hook_manager.cc b/src/hook_manager.cc
index d27bf731..6e3ae178 100644
--- a/src/hook_manager.cc
+++ b/src/hook_manager.cc
@@ -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());
}
}
diff --git a/src/line_modification.cc b/src/line_modification.cc
index 47e11e64..3e84fe50 100644
--- a/src/line_modification.cc
+++ b/src/line_modification.cc
@@ -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)
diff --git a/src/ranges.hh b/src/ranges.hh
index 2f288d0f..bd3edd9b 100644
--- a/src/ranges.hh
+++ b/src/ranges.hh
@@ -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)
{