This commit is contained in:
zouxiaohang
2015-11-10 10:08:19 +08:00
parent 44b37271ed
commit b728798dde
2 changed files with 6 additions and 4 deletions

View File

@@ -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;

View File

@@ -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);