summaryrefslogtreecommitdiff
path: root/src/client_manager.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2019-02-16 22:58:00 +1100
committerMaxime Coste <mawww@kakoune.org>2019-02-17 11:21:26 +1100
commit924f30840bdde1b18602b3db8b63e2efb3517c21 (patch)
tree2f3908e04c641c469ecf1cbed3c7a3624a4c65d7 /src/client_manager.cc
parent8135a44c6c3d9802e912153cb0e09f41f40d5af2 (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/client_manager.cc')
-rw-r--r--src/client_manager.cc24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/client_manager.cc b/src/client_manager.cc
index d90526a7..2f2a9e84 100644
--- a/src/client_manager.cc
+++ b/src/client_manager.cc
@@ -153,18 +153,22 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer)
Buffer* last = client->last_buffer();
context.change_buffer(last ? *last : BufferManager::instance().get_first_buffer());
}
- auto end = std::remove_if(m_free_windows.begin(), m_free_windows.end(),
- [&buffer](const WindowAndSelections& ws)
- { return &ws.window->buffer() == &buffer; });
-
- for (auto it = end; it != m_free_windows.end(); ++it)
+ 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.end());
+
+ for (auto&& removed_window : removed_windows)
{
- auto& win = it->window;
- win->run_hook_in_own_context(Hook::WinClose, win->buffer().name());
- m_window_trash.push_back(std::move(win));
+ removed_window->run_hook_in_own_context(Hook::WinClose,
+ removed_window->buffer().name());
+ m_window_trash.push_back(std::move(removed_window));
}
-
- m_free_windows.erase(end, m_free_windows.end());
}
void ClientManager::clear_window_trash()