diff options
| author | Maxime Coste <mawww@kakoune.org> | 2019-02-16 22:58:00 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2019-02-17 11:21:26 +1100 |
| commit | 924f30840bdde1b18602b3db8b63e2efb3517c21 (patch) | |
| tree | 2f3908e04c641c469ecf1cbed3c7a3624a4c65d7 /src/hook_manager.cc | |
| parent | 8135a44c6c3d9802e912153cb0e09f41f40d5af2 (diff) | |
Fix uses of std::remove_if
std::remove_if is not std::partition, it makes no guarantees on
the state of the objects past the new end (they usually are in a
moved-from state).
Diffstat (limited to 'src/hook_manager.cc')
| -rw-r--r-- | src/hook_manager.cc | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/hook_manager.cc b/src/hook_manager.cc index c5698c18..82f14512 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -36,13 +36,14 @@ void HookManager::remove_hooks(const Regex& regex) { for (auto& list : m_hooks) { - auto it = std::remove_if(list.begin(), list.end(), - [&](const std::unique_ptr<HookData>& h) - { return regex_match(h->group.begin(), h->group.end(), regex); }); - if (not m_running_hooks.empty()) // we are running some hooks, defer deletion - m_hooks_trash.insert(m_hooks_trash.end(), std::make_move_iterator(it), - std::make_move_iterator(list.end())); - list.erase(it, list.end()); + list.erase(std::remove_if(list.begin(), list.end(), + [this, ®ex](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()); } } |
