diff --git a/vector/data/one/code.cpp b/vector/data/one/code.cpp index 4360888..8aa982d 100644 --- a/vector/data/one/code.cpp +++ b/vector/data/one/code.cpp @@ -95,8 +95,11 @@ void TestInsert() for (int i = 0; i < 10; ++i) { v.push_back(i); } + std::cerr<<"Now back is"<< v.back()<::iterator it = v.begin(); it != v.end(); ++it) { std::cout << *it << " "; } diff --git a/vector/src/vector.hpp b/vector/src/vector.hpp index 769aaf7..fbc7ac3 100644 --- a/vector/src/vector.hpp +++ b/vector/src/vector.hpp @@ -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::construct(alloc, i, std::move(*(i - 1))); std::allocator_traits::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); }