From 3e54fa51445a3667f42a36d85aa9da9cccb51a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Wed, 24 Sep 2014 15:58:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9push=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E5=BE=97=E8=83=BD=E5=A4=9F=E5=BE=AA=E7=8E=AFpush=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E8=BF=9B=E5=85=A5circular=20buffer=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/CircularBuffer.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/TinySTL/CircularBuffer.h b/TinySTL/CircularBuffer.h index 8992b15..da5cf06 100644 --- a/TinySTL/CircularBuffer.h +++ b/TinySTL/CircularBuffer.h @@ -190,11 +190,18 @@ namespace TinySTL{ //************²åÈ룬ɾ³ýÏà¹Ø*********************** template void circular_buffer::push(const T& val){ - if (full()) + /*if (full()) throw; - indexOfTail = nextIndex(indexOfTail); - dataAllocator::construct(start_ + indexOfTail, val); - ++size_; + */ + if (full()){ + indexOfTail = nextIndex(indexOfTail); + dataAllocator::construct(start_ + indexOfTail, val); + indexOfHead = nextIndex(indexOfHead); + }else{ + indexOfTail = nextIndex(indexOfTail); + dataAllocator::construct(start_ + indexOfTail, val); + ++size_; + } } template void circular_buffer::pop(){