fill

  将value值填充整个区间,不能为OutputIterator,因为fill会用到first和last,outputIterator无法做相等的测试

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

fill_n

  会将数值value填充[first,first+n),返回值为first+n,可以用outputIterator

template <class OutputIterator,class size,class T>
OutputIterator fill_n( OutputIterator first, OutputIterator last,size n,const T& value);

generate

template <class ForwardIterator, class Generator>
void generate ( ForwardIterator first, ForwardIterator last, Generator gen )
{
    while (first != last)
    {
        *first = gen();
        ++first;
    }
}

  该函数是使用gen函数产生的值填充范围内元素的值。参数gen是一个接受空参数,并返回一个对应的值的函数或者是函数对象之类的。

generate_n

template <class OutputIterator, class Size, class Generator>
OutputIterator generate_n ( OutputIterator first, Size n,const Generator gen )
{
    )
    {
        *first = gen();
        ++first;
        --n;
    }
}

  返回值是first+n,generate和generate_n中的gen会被调用n(或first+n)次,而非只在循环外调用一次,这一点很重要,因为Generate不一定会在每次调用时候都返回相同的结果,因此generate允许从文件读入,取局部状态的值并更改。

#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;

class F
{
    private:
        static int i;
    public:
        int operator()()
        {
            return ++i;
        }
};
;

int main()
{
    vector<);
    generate(v.begin(),v.end(),rand);//调用c语言中的rand函数,填满v
    generate_n(v.begin(),,F());//调用函数对象
    for(auto i:v)
        cout<<i<<' ';
    cout<<endl;
    ;
}

填充整个区间(fill,fill_n,generate和generate_n)的更多相关文章

  1. STL: fill,fill_n,generate,generate_n

    fill Assigns the same new value to every element in a specified range. template<class ForwardIter ...

  2. C++ fill fill_n generate generate_n

    #include <iostream>#include <algorithm>#include <vector>#include <list>#incl ...

  3. 图像处理之泛洪填充算法(Flood Fill Algorithm)

    泛洪填充算法(Flood Fill Algorithm) 泛洪填充算法又称洪水填充算法是在很多图形绘制软件中常用的填充算法,最熟悉不过就是 windows paint的油漆桶功能.算法的原理很简单,就 ...

  4. HTML5 Canvas 填充与描边(Fill And Stroke)

    HTML5 Canvas 填充与描边(Fill And Stroke) 演示HTML5 Canvas Fill 与Stroke文字效果,基于Canvas如何实 现纹理填充与描边. 一:颜色填充与描边 ...

  5. 图像处理------泛洪填充算法(Flood Fill Algorithm) 油漆桶功能

    泛洪填充算法(Flood Fill Algorithm) 泛洪填充算法又称洪水填充算法是在很多图形绘制软件中常用的填充算法,最熟悉不过就是 windows paint的油漆桶功能.算法的原理很简单,就 ...

  6. STL_算法_填充新值(fill、fill_n、generate、generate_n)

    C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) 全部容器适用 fill(b,e,v)             //[b,e)   填充成v fill_n(b,n,v)     ...

  7. c++ 容器填充指定长度(fill_n)

    #include <iostream> // cout #include <algorithm> // fill_n #include <vector> // ve ...

  8. 变易算法 - STL算法

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/mutating-algorithms.h ...

  9. STL--STL和她的小伙伴们:

    STL--概述: 标准模板库(StandardTemplateLibrary,STL),是C++程序设计语言标准模板库.STL是由Alexander Stepanov.Meng Lee和David R ...

随机推荐

  1. Linux alias别名命令

    首先介绍一下命令的别名,怎么查看的呢? 咱们使用which命令就可以查看的到它完整的命令是怎样的 [root@master ~]# which ls alias ls='ls --color=auto ...

  2. The issue about the GMT paper can't display all the seismograms

    I try to display seismograms using 'pssac' by the command: gmt pssac *.z -JX20c/40c -R0/// -Bx20+l'T ...

  3. SharePoint Framework 企业向导(十)

    博客地址:http://blog.csdn.net/FoxDave 接上一讲 SharePoint Framework部署范围 对于SharePoint Framework解决方案,只有一个部署范围: ...

  4. codeforces1003D(贪心)

    D. Coins and Queries time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. 实现简单的shell sed替换功能

    通过脚本传参数可以实现替换 # -*-coding:utf-8-*- # Author:sunhao import sys f = open('yesterday','r',encoding='utf ...

  6. php优秀框架codeigniter学习系列——CI_URI类学习

    这篇文章主要介绍CI核心框架工具类CI_URI. 该类主要用来解析uri和决定路由的.关于URI和URL的关系请参考这位朋友的文章.简单来说URI是唯一定位的资源,URL是唯一资源的一个网络可能访问路 ...

  7. divide&conquer:find max array

    package max_subarrayy;import java.lang.Math;public class max_subarrayy { private static int[] array; ...

  8. 【Python】unittest-2-断言

    Unittest中的断言 1.  python unintest单元测试框架提供了一整套内置的断言方法. (1)如果断言失败,则抛出一个AssertionError,并标识该测试为失败状态 (2)如果 ...

  9. RPi 3B 无线连接配置

    /********************************************************************** * RPi 3B 无线连接配置 * 说明: * 树莓派3 ...

  10. SDM(Supervised Descent Method and its Applications to Face Alignment )

    sdm SDM 人脸对齐的核心内容很简单,就是特征到偏移量的映射:                                           Ix = R I 是特征,x是映射矩阵,R是偏移 ...