提交 b728798d 编写于 作者: Z zouxiaohang

bug fix

上级 44b37271
......@@ -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;
......
......@@ -244,7 +244,7 @@ namespace TinySTL{
template <class InputIterator>
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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册