From fc9637a9d809c4fb04711f8355d7a717a0b0f69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Thu, 25 Sep 2014 08:07:38 +0800 Subject: [PATCH] bug fix --- TinySTL/CircularBuffer.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/TinySTL/CircularBuffer.h b/TinySTL/CircularBuffer.h index 12f5334..33d88ea 100644 --- a/TinySTL/CircularBuffer.h +++ b/TinySTL/CircularBuffer.h @@ -193,7 +193,7 @@ namespace TinySTL{ size_ = n; } } - int nextIndex(int index){ return ++index % N; } + int nextIndex(int index){ return (index + 1) % N; } void copyAllMembers(const circular_buffer& cb){ start_ = cb.start_; finish_ = cb.finish_; @@ -277,11 +277,14 @@ namespace TinySTL{ template std::ostream& operator <<(std::ostream& os, circular_buffer& cb){ - os << "("; - for (auto it = cb.first(); it != cb.last(); ++it){ - os << *it << ", "; + circular_buffer::size_type size = cb.size(); + if (!cb.empty()){ + os << "("; + for (auto it = cb.first(); it != cb.last() && size != 0; ++it, --size){ + os << *it << ", "; + } + os << *(cb.last()) << ")"; } - os << *(cb.last()) << ")"; return os; } }