STL算法学习-- for_each( ) 与 transform()
2012-07-09 12:14
357 查看
for_each() 对某区间无素执行某种操作.
void print( int &elem)
{
cout<<elem<<endl;
}
for_each(coll.begin(), coll.end(), print) ;
回为元素以引用方式传递,可以改变区间内的元素,.for_each()还可以返回传递进去的函数对像的副本。
transform() [b]对某区间无素执行某种操作.操作返回被改动后的元素 可以将操作的结果放到指定的区间[/b]
void fun( int elem)
{
retun elem*elem;
}
transform(coll.begin(), coll.end(), coll.begin(), fun);
transform() 另一个形式,将两个区间的元素放到一个二元操作中加工,返回结果
transform(coll.begin(), coll.end(), coll2.begin(), coll.begin(), fun);
void print( int &elem)
{
cout<<elem<<endl;
}
for_each(coll.begin(), coll.end(), print) ;
回为元素以引用方式传递,可以改变区间内的元素,.for_each()还可以返回传递进去的函数对像的副本。
transform() [b]对某区间无素执行某种操作.操作返回被改动后的元素 可以将操作的结果放到指定的区间[/b]
void fun( int elem)
{
retun elem*elem;
}
transform(coll.begin(), coll.end(), coll.begin(), fun);
transform() 另一个形式,将两个区间的元素放到一个二元操作中加工,返回结果
transform(coll.begin(), coll.end(), coll2.begin(), coll.begin(), fun);
相关文章推荐
- STL学习之十四:常用算法 for_each 和 transform以及adjacent_find的示例代码
- C++ STL 中有关于for_each() 和 transform() 算法
- STL遍历算法 “for_each ”,“transform”
- STL学习笔记----9.STL算法之 for_each()
- STL中的两个算法for_each与transform
- STL常用遍历算法for_each和transform的比较
- STL常用遍历算法for_each和transform的比较
- 【C++ STL学习之六】STL算法之for_each
- STL通用算法: for_each,c++11标准范围for,transform.
- 【C++ STL学习之六】STL算法之for_each
- STL_算法 for_each 和 transform 比较
- STL算法 ------- transform() 与 for_each()比较
- 【C++ STL学习之六】STL算法之for_each
- STL算法(19)——for_each()和transform()的比较
- STL_Algorithm5-math: random_shuffle, count, count_if, min_element, max_element, accumulate, for_each, transform
- STL学习之for_each的用法
- C++ STL 学习 :for_each与仿函数(functor)
- STL_算法_for_each
- STL运算算法-for_each()
- STL fill()填充算法以及for_each()算法 取容器中的最大最小值min_element,max_element