From f9ff982521aad9c4de24af92713f3cf9f3ca9c11 Mon Sep 17 00:00:00 2001 From: Dawid Drozd Date: Tue, 29 Nov 2022 12:09:23 +0400 Subject: [PATCH] Fix compile error Shame on me. --- .../dexode/eventbus/stream/ProtectedEventStream.hpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/src/dexode/eventbus/stream/ProtectedEventStream.hpp b/lib/src/dexode/eventbus/stream/ProtectedEventStream.hpp index ca118c7..40d574b 100644 --- a/lib/src/dexode/eventbus/stream/ProtectedEventStream.hpp +++ b/lib/src/dexode/eventbus/stream/ProtectedEventStream.hpp @@ -39,10 +39,14 @@ public: { const auto countElements = std::min(limit, _queue.size()); processEvents.reserve(countElements); - std::move(_queue.begin(), - std::next(_queue.begin(), countElements), - std::back_inserter(processEvents)); - _queue.erase(_queue, std::next(_queue.begin(), countElements)); + auto begin = _queue.begin(); + auto end = std::next(begin, countElements); + + // moved-from range will still contain valid values of the appropriate type, but not + // necessarily the same values as before the move. Iterators should be still valid. + // see: https://en.cppreference.com/w/cpp/algorithm/move + std::move(begin, end, std::back_inserter(processEvents)); + _queue.erase(begin, end); } }