Skip to content
New issue

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

deque的insert_dispatch,对输入迭代器进行了--操作:auto cur = --last; #158

Open
Peas-Li opened this issue Oct 19, 2024 · 1 comment

Comments

@Peas-Li
Copy link

Peas-Li commented Oct 19, 2024

// insert_dispatch 函数
template
template
void deque::
insert_dispatch(iterator position, IIter first, IIter last, input_iterator_tag)
{
if (last <= first) return;
const size_type n = mystl::distance(first, last);
const size_type elems_before = position - begin_;
if (elems_before < (size() / 2))
{
require_capacity(n, true);
}
else
{
require_capacity(n, false);
}
position = begin_ + elems_before;
auto cur = --last;
for (size_type i = 0; i < n; ++i, --cur)
{
insert(position, *cur);
}
}

@frederick-vs-ja
Copy link
Contributor

last <= first 这里开始就不对了,只有随机访问迭代才保证能这样比较。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants