diff --git a/TinySTL/Detail/Vector.impl.h b/TinySTL/Detail/Vector.impl.h index 9e1c3f1df43c94377aa467c85bb2f6eacdec31c1..d2cb2e8e060955f9ca06fd3c6cc7a29df7fcd2ea 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 5d81ca17662c2f9fc53a36539df44731ce0b75a7..ec83564f02e5ffed2088acd47668cb4c91fa14f2 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);