From e297f98bb13a5f390bae0a82fd5a9d73e9782a1a 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, 22 Oct 2014 19:29:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dclear=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Deque.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/TinySTL/Deque.h b/TinySTL/Deque.h index 843cdf0..1aa13b7 100644 --- a/TinySTL/Deque.h +++ b/TinySTL/Deque.h @@ -171,7 +171,10 @@ namespace TinySTL{ deque(const deque& x); ~deque(){ - clear(); + for (int i = 0; i != mapSize_; ++i) + if (!map_[i]) + dataAllocator::deallocate(map_[i], getBuckSize()); + delete[] map_; } deque& operator= (const deque& x); @@ -202,8 +205,10 @@ namespace TinySTL{ void clear(){ for (int i = 0; i != mapSize_; ++i) if (!map_[i]) - dataAllocator::deallocate(map_[i], getBuckSize()); - delete[] map_; + dataAllocator::destroy(map_[i], map_[i] + getBuckSize()); + mapSize_ = 0; + beg_.mapIndex_ = end_.mapIndex_ = mapSize_ / 2; + beg_.cur_ = end_.cur_ = map_[mapSize_ / 2]; } private: T *getANewBuck(){