cplusplus系列>algorithm>std::for_each
http://www.cplusplus.com/reference/algorithm/for_each/
对一个序列应用函数。可以是函数指针,或者是functor。
// for_each example
#include <iostream> // std::cout
#include <algorithm> // std::for_each
#include <vector> // std::vector void myfunction (int i) { // function:
std::cout << ' ' << i;
} struct myclass { // function object type:
void operator() (int i) {std::cout << ' ' << i;}
} myobject; int main () {
std::vector<int> myvector;
myvector.push_back();
myvector.push_back();
myvector.push_back(); std::cout << "myvector contains:";
for_each (myvector.begin(), myvector.end(), myfunction);
std::cout << '\n'; // or:
std::cout << "myvector contains:";
for_each (myvector.begin(), myvector.end(), myobject);
std::cout << '\n'; return ;
}
cplusplus系列>algorithm>std::for_each的更多相关文章
- hdu 1053 (huffman coding, greedy algorithm, std::partition, std::priority_queue ) 分类: hdoj 2015-06-18 19:11 22人阅读 评论(0) 收藏
huffman coding, greedy algorithm. std::priority_queue, std::partition, when i use the three commente ...
- c++ stl algorithm: std::fill, std::fill_n
std::fill 在[first, last)范围内填充值 #include <iostream> #include <vector> #include <algori ...
- c++ stl algorithm: std::find, std::find_if
std::find: 查找容器元素, find仅仅能查找容器元素为<基本数据类型> [cpp] view plaincopy #include <iostream> #incl ...
- C++ 头文件系列 (algorithm)
简介 algorithm头文件是C++的标准算法库,它主要应用在容器上. 因为所有的算法都是通过迭代器进行操作的,所以算法的运算实际上是和具体的数据结构相分离的 ,也就是说,具有低耦合性. 因此,任何 ...
- cplusplus系列>utility>pair
http://www.cplusplus.com/reference/utility/pair/ 用于存储一对异构对象 // Compile: g++ -std=c++11 pair.cpp #inc ...
- for_each(c++11)
http://www.cplusplus.com/reference/algorithm/for_each/ template<class InputIterator, class Functi ...
- algorithm之不变序列操作
概述:不变序列算法,参见http://www.cplusplus.com/reference/algorithm/ /* std::for_each template <class InputI ...
- STL for_each()
http://www.cplusplus.com/reference/algorithm/for_each/ std::move()用于c++11 http://www.cplusplus.com/r ...
- STL_advance distance prev next
template<class InputIterator> typename iterator_traits<InputIterator>::difference_type d ...
随机推荐
- JQuery实现的动态Table(转)
这个例子做的不错,转载备份. 原文:http://www.cnblogs.com/linjiqin/archive/2013/06/21/3148181.html $("#mytable t ...
- spring mvc为何多注入了个SimpleUrlHandlerMapping?
最近在调试项目时,debug DispatcherServlet时,发现handlerMappings属性包含了RequestMappingHandlerMapping.SimpleUrlHandle ...
- Java反射机制(创建Class对象的三种方式)
1:了解什么是反射机制? 在通常情况下,如果有一个类,可以通过类创建对象:但是反射就是要求通过一个对象找到一个类的名称: 2:在反射操作中,握住一个核心概念: 一切操作都将使用Object完成,类 ...
- C:指针、数据类型、格式化输入输出、输入函数的坑点
指针.数据类型.格式化输入输出.输入函数的坑点 有时候我们迷茫的时候,坚持就是最好的选择. 1.指针的分类为什么很重要? 参考 答:因为指针会根据相应的类型取对应长度的数据,类型决定所取数据的长度.如 ...
- ReentrantLock
与synchronized相同并发性和内存语义. [新增特性]锁投票.定时锁等候.可中断锁等候.更少时间调度线程. [用法注意点]Lock必须在finally块中释放. Lock lock = new ...
- JDBC Connection
[ http://shift-alt-ctrl.iteye.com/blog/1967020] 关于JDBC中关于Connection的两个疑问: 1.Connection实例是线程安全的吗? ...
- 通过点击取消按钮关闭dialog窗口
- Extjs Google的Suggest的自动提示 从后台取数据
//服务器取数据 var remoteStore = Ext.create('Ext.data.Store', { proxy: ({ type: "ajax", url:&quo ...
- Winform学习手册(目录)
一.基础: WINFORM学习笔记——创建Winform项目 WINFORM学习手册——TextBox.Lable.Button WINFORM学习笔记——窗体生命周期 WINFORM学习手册——对话 ...
- 双网卡绑定-bond0
网卡绑定就是多张网卡逻辑上作为一张网卡用.可分为,负载均衡绑定和冗余绑定两种. 1.编辑虚拟网络接口配置文件 [root@test~]# more /etc/sysconfig/network-scr ...