粗略了解fill与fill_n

以前只知道数组赋值时用memset();

而这几天却了解到了一个函数:fill();

感觉以后会有用吧。。。

std::fill

template <class ForwardIterator, class T>
  void fill (ForwardIterator first, ForwardIterator last, const T& val);
Fill range with value

Assigns val to all the elements in the range [first,last).

The behavior of this function template is equivalent to:

1
2
3
4
5
6
7
8
template <class ForwardIterator, class T>
  void fill (ForwardIterator first, ForwardIterator last, const T& val)
{
  while (first != last) {
    *first = val;
    ++first;
  }
}
 

这个函数可以将所求区间的每一个单元的值更改为新的值;

(未完待续)

 

posted @ 2017-10-29 21:42  Slager_Z  阅读(468)  评论(0编辑  收藏  举报
博客园 首页 私信博主 显示目录 隐藏目录 管理 动画