Merge branch 'master' of https://github.com/zouxiaohang/TinySTL.git
This commit is contained in:
@@ -144,12 +144,16 @@ namespace TinySTL{
|
|||||||
difference_type locationNeed = distance(first, last);//last - first;
|
difference_type locationNeed = distance(first, last);//last - first;
|
||||||
|
|
||||||
if (locationLeft >= locationNeed){
|
if (locationLeft >= locationNeed){
|
||||||
iterator tempPtr = end() - 1;
|
if (finish_ - position > locationNeed){
|
||||||
for (; tempPtr - position >= 0; --tempPtr){//move the [position, finish_) back
|
TinySTL::uninitialized_copy(finish_ - locationNeed, finish_, finish_);
|
||||||
//*(tempPtr + locationNeed) = *tempPtr;//bug
|
std::copy_backward(position, finish_ - locationNeed, finish_);
|
||||||
construct(tempPtr + locationNeed, *tempPtr);
|
std::copy(first, last, position);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
iterator temp = TinySTL::uninitialized_copy(first + (finish_ - position), last, finish_);
|
||||||
|
TinySTL::uninitialized_copy(position, finish_, temp);
|
||||||
|
std::copy(first, first + (finish_ - position), position);
|
||||||
}
|
}
|
||||||
TinySTL::uninitialized_copy(first, last, position);
|
|
||||||
finish_ += locationNeed;
|
finish_ += locationNeed;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|||||||
@@ -187,6 +187,47 @@ namespace TinySTL{
|
|||||||
assert(foo != bar);
|
assert(foo != bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestItem()
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
TestItem(const TestItem & other)
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~TestItem()
|
||||||
|
{
|
||||||
|
--count;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getCount()
|
||||||
|
{
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
static int count;
|
||||||
|
};
|
||||||
|
int TestItem::count = 0;
|
||||||
|
|
||||||
|
void testCase15()
|
||||||
|
{
|
||||||
|
assert(TestItem::getCount() == 0);
|
||||||
|
{
|
||||||
|
typedef TinySTL::vector<TestItem> TVector;
|
||||||
|
TVector t(10);
|
||||||
|
t.push_back(TestItem());
|
||||||
|
t.push_back(TestItem());
|
||||||
|
t.push_back(TestItem());
|
||||||
|
t.insert(t.begin(), t.begin(), t.begin() + 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
assert(TestItem::getCount() == 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void testAllCases(){
|
void testAllCases(){
|
||||||
testCase1();
|
testCase1();
|
||||||
@@ -203,6 +244,7 @@ namespace TinySTL{
|
|||||||
testCase12();
|
testCase12();
|
||||||
testCase13();
|
testCase13();
|
||||||
testCase14();
|
testCase14();
|
||||||
|
testCase15();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user