Skip to content

Commit

Permalink
range_init 使用distance判断迭代器之间距离
Browse files Browse the repository at this point in the history
  • Loading branch information
infdahai authored Jan 7, 2023
1 parent e64c1cc commit b56bbbf
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 b56bbbf

Please sign in to comment.