From b728798ddea8c807a9d093f55341afd049c543c8 Mon Sep 17 00:00:00 2001 From: zouxiaohang <1210603696@qq.com> Date: Tue, 10 Nov 2015 10:08:19 +0800 Subject: [PATCH] bug fix --- TinySTL/Detail/Vector.impl.h | 8 +++++--- TinySTL/String.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/TinySTL/Detail/Vector.impl.h b/TinySTL/Detail/Vector.impl.h index 9e1c3f1..d2cb2e8 100644 --- a/TinySTL/Detail/Vector.impl.h +++ b/TinySTL/Detail/Vector.impl.h @@ -141,12 +141,13 @@ namespace TinySTL{ InputIterator last, std::false_type){ difference_type locationLeft = endOfStorage_ - finish_; // the size of left storage - difference_type locationNeed = last - first; + difference_type locationNeed = distance(first, last);//last - first; if (locationLeft >= locationNeed){ iterator tempPtr = end() - 1; for (; tempPtr - position >= 0; --tempPtr){//move the [position, finish_) back - *(tempPtr + locationNeed) = *tempPtr; + //*(tempPtr + locationNeed) = *tempPtr;//bug + construct(tempPtr + locationNeed, *tempPtr); } TinySTL::uninitialized_copy(first, last, position); finish_ += locationNeed; @@ -165,7 +166,8 @@ namespace TinySTL{ if (locationLeft >= locationNeed){ auto tempPtr = end() - 1; for (; tempPtr - position >= 0; --tempPtr){//move the [position, finish_) back - *(tempPtr + locationNeed) = *tempPtr; + //*(tempPtr + locationNeed) = *tempPtr;//bug + construct(tempPtr + locationNeed, *tempPtr); } TinySTL::uninitialized_fill_n(position, n, value); finish_ += locationNeed; diff --git a/TinySTL/String.h b/TinySTL/String.h index 5d81ca1..ec83564 100644 --- a/TinySTL/String.h +++ b/TinySTL/String.h @@ -244,7 +244,7 @@ namespace TinySTL{ template string::iterator string::insert(iterator p, InputIterator first, InputIterator last){ auto lengthOfLeft = capacity() - size(); - size_t lengthOfInsert = last - first; + size_t lengthOfInsert = distance(first, last); if (lengthOfInsert <= lengthOfLeft){ for (iterator it = finish_ - 1; it >= p; --it){ *(it + lengthOfInsert) = *(it);