We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
你好 我看过你的insert函数,存在一点问题,下面是我的测试代码
namespace JJ { #include <iostream> using namespace std; class TestItem { public: TestItem() { ++count; cout << "Construct" << endl; } TestItem(const TestItem & other) { ++count; cout << "Copy Construct" << endl; } virtual ~TestItem() { --count; cout << "Destructor" << endl; } static int getCount() { return count; } private: static int count; }; int TestItem::count = 0; void testCase16() { assert(TestItem::getCount() == 0); { typedef TinySTL::vector<TestItem> TVector; //typedef std::vector<TestItem> TVector; TVector t(10); t.push_back(TestItem()); t.push_back(TestItem()); t.push_back(TestItem()); //t.insert(t.begin(), 10, TestItem()); cout << t.capacity() << endl; t.insert(t.begin(), t.begin(), t.begin() + 1); cout << t.size() << endl; t.clear(); } assert(TestItem::getCount() == 0); } }
你的这个函数的实现里面,调用了
void insert_aux(iterator position, InputIterator first, InputIterator last, std::false_type);
The text was updated successfully, but these errors were encountered:
问题在哪
Sorry, something went wrong.
assert(TestItem::getCount() == 0); 不满足了
for (; tempPtr - position >= 0; --tempPtr){//move the [position, finish_) back construct(tempPtr + locationNeed, *tempPtr); } ...
这段代码应该是后移插入点之后的元素,但是应该分成两种情况来对待
TinySTL::uninitialized_copy(first, last, position);
这段代码应该是用来插入新增的元素,同样需要考虑上面说到的两种情况
我觉得应该改成这样比较好点
if (locationLeft >= locationNeed) { if (finish_ - position > locationNeed) { TinySTL::uninitialized_copy(finish_ - locationNeed, finish_, finish_); std::copy_backward(position, finish_ - locationNeed, finish_); 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); }
No branches or pull requests
你好
我看过你的insert函数,存在一点问题,下面是我的测试代码
你的这个函数的实现里面,调用了
The text was updated successfully, but these errors were encountered: