for_each用法
来源:互联网 发布:解封电脑机器码软件 编辑:程序博客网 时间:2024/06/05 17:51
template <class InputIterator, class Function> Function for_each (InputIterator first, InputIterator last, Function f);
<algorithm>
Apply function to range
Applies function f to each of the elements in the range [first,last).
The behavior of this template function is equivalent to:
template<class InputIterator, class Function> Function for_each(InputIterator first, InputIterator last, Function f) { while ( first!=last ) f(*first++); return f; }
#include<iostream>#include<algorithm>#include<vector>using namespace std;struct info{int key;int value;bool operator()(info A){cout<<A.key<<"\t"<<A.value<<endl;return 1;}};int main(){vector<info>vec(4);int i;for(i=0;i<4;i++){vec[i].key=i;vec[i].value=2*i;}for_each(vec.begin(),vec.end(),info());}
Parameters
- first, last
- Input iterators to the initial and final positions in a sequence. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
- f
- Unary function taking an element in the range as argument. This can either be a pointer to a function or an object whose class overloads operator().
Its return value, if any, is ignored.
Return value
The same as f.- for_each用法
- (STL)for_each、find_if用法
- STL for_each,find_if用法
- for_each的用法
- stl for_each某种用法
- for_each函数用法
- STL::for_each用法
- for_each的用法
- for_each的用法
- STL for_each 用法
- for_each的用法
- for_each的用法
- for_each()的用法
- for_each的用法
- c++ for_each 用法
- for_each函数用法
- algorithm中for_each用法
- 一个for_each用法小例子
- AT原理
- ZOJ Problem Set - 1243 URLs
- 黑马程序员_我的黑马程序员之路
- 数字集成电路经典教材
- __attribute__宏与link脚本的用法
- for_each用法
- 用C#创建XML
- 通过数据库服务器触发器控制机器访问
- [IT 男人帮 -11/03] 几个软件研发团队管理的小问题
- Windows下多线程常用函数
- 单元格内容超出宽度时隐藏多余部分
- OSC首发:android中的左右滑屏实现By ViewPager
- UI开发第十六篇——分享一个popuwindow实例
- Linux的进程管理和作业控制