From bad728446564bc705ee5b348015a8ef0afcb7336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20=C5=A0milauer?= Date: Sat, 9 Nov 2019 09:30:27 +0100 Subject: [PATCH] Fix cicular_q::size() --- include/spdlog/details/circular_q.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/spdlog/details/circular_q.h b/include/spdlog/details/circular_q.h index aac4223f..d07f0725 100644 --- a/include/spdlog/details/circular_q.h +++ b/include/spdlog/details/circular_q.h @@ -75,7 +75,14 @@ public: // Return number of elements actually stored size_t size() const { - return (tail_ - head_) % max_items_; + if (tail_ > head_) + { + return (tail_ - head_) % max_items; + } + else + { + return max_items - (head_ - tail_ ) % max_items; + } } // Return const reference to item by index.