diff --git a/src/commands.cc b/src/commands.cc index 805a42343..c86cc15cd 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1572,13 +1572,10 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) }; if (*bufnames == "*") { - // copy buffer list as we might be mutating the buffer list - // in the loop. - auto ptrs = BufferManager::instance() | - transform(std::mem_fn(&std::unique_ptr::get)) | - filter([](Buffer* buf) { return not (buf->flags() & Buffer::Flags::Debug); }); - Vector> buffers{ptrs.begin(), ptrs.end()}; - for (auto buffer : buffers) + for (auto&& buffer : BufferManager::instance() + | transform(std::mem_fn(&std::unique_ptr::get)) + | filter([](Buffer* buf) { return not (buf->flags() & Buffer::Flags::Debug); }) + | gather>>()) // gather as we might be mutating the buffer list in the loop. context_wrap_for_buffer(*buffer); } else