STL源代码分析(ch2 内存分配)uninitialized_fill
Posted thefist11
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STL源代码分析(ch2 内存分配)uninitialized_fill相关的知识,希望对你有一定的参考价值。
1.
// uninitialized_fill
// 在 [first, last) 区间内填充元素值
template <class ForwardIter, class T>
void uninitialized_fill(ForwardIter first, ForwardIter last, const T& value)
mystl::unchecked_uninit_fill(first, last, value,
std::is_trivially_copy_assignable<
typename iterator_traits<ForwardIter>::
value_type>);
->
template <class ForwardIter, class T>
void
unchecked_uninit_fill(ForwardIter first, ForwardIter last, const T& value, std::true_type)
mystl::fill(first, last, value);
template <class ForwardIter, class T>
void
unchecked_uninit_fill(ForwardIter first, ForwardIter last, const T& value, std::false_type)
auto cur = first;
try
for (; cur != last; ++cur)
mystl::construct(&*cur, value);
catch (...)
for (;first != cur; ++first)
mystl::destroy(&*first);
1.1 fill
// fill
// 为 [first, last)区间内的所有元素填充新值
template <class ForwardIter, class T>
void fill(ForwardIter first, ForwardIter last, const T& value)
fill_cat(first, last, value, iterator_category(first));
->
template <class ForwardIter, class T>
void fill_cat(ForwardIter first, ForwardIter last, const T& value,
mystl::forward_iterator_tag)
for (; first != last; ++first)
*first = value;
template <class RandomIter, class T>
void fill_cat(RandomIter first, RandomIter last, const T& value,
mystl::random_access_iterator_tag)
fill_n(first, last - first, value);
以上是关于STL源代码分析(ch2 内存分配)uninitialized_fill的主要内容,如果未能解决你的问题,请参考以下文章
STL源代码分析(ch2 内存分配)uninitialized_fill
STL源代码分析(ch2 内存分配)uninitialized_fill