首页 > 代码库 > c++11:iota
c++11:iota
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。