fix error in insert
This commit is contained in:
@ -95,8 +95,11 @@ void TestInsert()
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
v.push_back(i);
|
||||
}
|
||||
std::cerr<<"Now back is"<< v.back()<<std::endl;
|
||||
v.insert(v.begin() + 3, 100);
|
||||
std::cerr<<"Now back is"<< v.back()<<std::endl;
|
||||
v.insert(v.begin() + 5, 200);
|
||||
std::cerr<<"Now back is"<< v.back()<<std::endl;
|
||||
for (sjtu::vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
|
||||
std::cout << *it << " ";
|
||||
}
|
||||
|
@ -368,7 +368,7 @@ class vector {
|
||||
raw_end = raw_beg + current_length;
|
||||
allocated_length = new_allocated_length;
|
||||
}
|
||||
for (T *i = raw_end - 1; i != pos.raw_pointer; --i) {
|
||||
for (T *i = raw_end; i != pos.raw_pointer; --i) {
|
||||
std::allocator_traits<decltype(alloc)>::construct(alloc, i, std::move(*(i - 1)));
|
||||
std::allocator_traits<decltype(alloc)>::destroy(alloc, i - 1);
|
||||
}
|
||||
@ -398,7 +398,7 @@ class vector {
|
||||
raw_end = raw_beg + current_length;
|
||||
allocated_length = new_allocated_length;
|
||||
}
|
||||
for (T *i = raw_end - 1; i != raw_beg + ind; --i) {
|
||||
for (T *i = raw_end; i != raw_beg + ind; --i) {
|
||||
alloc.construct(i, std::move(*(i - 1)));
|
||||
alloc.destroy(i - 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user