Skip to content

Commit

Permalink
Merge pull request #121 from infdahai/patch-3
Browse files Browse the repository at this point in the history
range_init 使用distance判断迭代器之间距离
  • Loading branch information
Alinshans authored Jan 14, 2023
2 parents ccfd1a0 + b56bbbf commit acc07e0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions MyTinySTL/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,9 @@ template <class Iter>
void vector<T>::
range_init(Iter first, Iter last)
{
const size_type init_size = mystl::max(static_cast<size_type>(last - first),
static_cast<size_type>(16));
init_space(static_cast<size_type>(last - first), init_size);
const size_type len = mystl::distance(first, last);
const size_type init_size = mystl::max(len, static_cast<size_type>(16));
init_space(len, init_size);
mystl::uninitialized_copy(first, last, begin_);
}

Expand Down

0 comments on commit acc07e0

Please sign in to comment.