码迷,mamicode.com
首页 > 编程语言 > 详细

c++11:iota

时间:2014-10-13 14:34:19      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   strong   

iota:

Fills the range [first, last) with sequentially(循环的) increasing values, starting with value and repetitively(重复地) evaluating ++value.

Parameters

  first, last:the range of elemets to fill with sequentially increasing values starting with value

 

  vaule: intial value to store, the expression ++value must be well-formed  

Return value

(none)

 

Possible implementation

template<class ForwardIterator, class T>
void iota(ForwardIterator first, ForwardIterator last, T value)
{
    while(first != last) {
        *first++ = value;
        ++value;
    }
}

 

我的例子:

  1 #include <numeric>
  2 #include <vector>
  3 #include <iostream>
  4 using namespace std;
  5 
  6 int main()
  7 {
  8     int a[5];
  9     iota(a, a+5, 10);
 10     for (auto &r: a)
 11         cout << r ;
 12     cout << endl;
 13 
 14     vector<int> va(5);
 15     iota(va.begin(), va.end(), 4);
 16     for (auto &v : va)
 17         cout << v << " ";
 18     cout << endl;
 19 
 20     vector<vector<int>::iterator> vb(va.size());
 21     itoa(vb.begin(), vb.end(), va.begin());
 22     for (auto &v : vb)
 23         cout << *v << " ";
 24     cout << endl;
 25 }

 

输出结果:

  10,11, 12, 13, 14 

  10,11, 12, 13, 14 

  10,11, 12, 13, 14 

c++11:iota

标签:style   blog   http   color   io   os   ar   for   strong   

原文地址:http://www.cnblogs.com/457220157-FTD/p/4021902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!