美文网首页
C++ STL iota 函数说明

C++ STL iota 函数说明

作者: book_02 | 来源:发表于2019-09-26 07:42 被阅读0次

说明

iota用一个从value递增的数列给[first, last)的容器赋值
等效于

*(d_first)   = value;
*(d_first+1) = ++value;
*(d_first+2) = ++value;
*(d_first+3) = ++value;
...

C++11 才引入,之前版本没有此函数

头文件

#include <numeric>

名称来源

itoa 是 希腊语的第九个字母,读[aɪ'otə]
这个名称是从APL编程语言借鉴过来的。

For example, the integer function denoted by ι produces a vector of the first n integers when applied to the argument n, …

例子


#include <iostream>
#include <vector>
#include <numeric>

int main()
{
    std::vector<int> nums(10);

    for (int i : nums) {
        std::cout << i << "\t";
    }
    std::cout << std::endl;

    std::iota(nums.begin(), nums.end(), 5); // fill nums with 5, 6, 7, 8...

    for (int i : nums) {
        std::cout << i << "\t";
    }
    std::cout << std::endl;

    system("pause");
    return 0;
}

结果:

0       0       0       0       0       0       0       0       0       0
5       6       7       8       9       10      11      12      13      14

参考

http://www.cplusplus.com/reference/numeric/iota/
https://stackoverflow.com/questions/9244879/what-does-iota-of-stdiota-stand-for

相关文章

  • C++ STL iota 函数说明

    说明 iota用一个从value递增的数列给[first, last)的容器赋值等效于 C++11 才引入,之前版...

  • C++ STL transform 函数说明

    说明 简而言之,transform是用来做转换的。转换有两种:一元转换和二元转换。 一元转换是对容器给定范围内的每...

  • C++库

    标准库C++标准库,包括了STL容器,算法和函数等。C++ Standard Library:是一系列类和函数的集...

  • GeekBand C++ STL与泛型编程 第一周学习笔记

    STL概述 C++标准库包含STL和一些其他内容 STL有六大组件: 容器,分配器,算法,迭代器,适配器,仿函数 ...

  • [资源]C++ 程序员必收藏

    C++ 资源大全中文版 标准库 C++标准库,包括了STL容器,算法和函数等。 C++ Standard Libr...

  • 读书笔记17.06.03

    C++ STL:Listlist是C++标准模版库(STL,Standard Template Library)中...

  • [C++] STL 容器

    参考:[C++] STL 容器 (一) - 基本介紹[C++] STL 容器 (二) - Iterator 部分示例:

  • C++后端开发的踩坑整理

    C++开发的一些经验和踩坑整理 STL相关的坑 1. std::sort()函数要求严格弱序 STL文档中要求so...

  • C++ STL back_inserter 函数说明

    说明 back_inserter用于在末尾插入元素。实现方法是构造一个迭代器,这个迭代器可以在容器末尾添加元素。这...

  • C++ STL equal_range 函数说明

    说明 equal_range 返回范围[first,last)内等于指定值val的子范围的迭代器。 注意的是使用这...

网友评论

      本文标题:C++ STL iota 函数说明

      本文链接:https://www.haomeiwen.com/subject/blhcyctx.html