首页 > 编程语言 > 详细

c++11:iota

时间:2014-10-13 12:35:30      阅读:276      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!