Effective STL学习笔记-条款36
来源:互联网 发布:淘宝质检报告 编辑:程序博客网 时间:2024/06/06 12:26
了解copy_if的正确实现
先看copy和copy_if的使用小demo:
vector<int> from(10); std::iota(from.begin(), from.end(), 0); //0 - 9 vector<int> to; //copy std::copy(from.begin(), from.end(), back_inserter(to)); std::copy(to.begin(), to.end(), std::ostream_iterator<int>(std::cout, " ")); vector<int> to_; //copy_if std::copy_if(from.begin(), from.end(), back_inserter(to_), [=](const int value) { return value > 5; }); std::copy(to_.begin(), to_.end(), std::ostream_iterator<int>(std::cout, " "));
打印如下,0-9是to的容器你内容,6-9是to_的容器内容:
copy和copy_if的实现如下:
template<class InputIt, class OutputIt>OutputIt copy(InputIt first, InputIt last, OutputIt d_first){ while (first != last) { *d_first++ = *first++; } return d_first;}template<class InputIt, class OutputIt, class UnaryPredicate>OutputIt copy_if(InputIt first, InputIt last, OutputIt d_first, UnaryPredicate pred){ while (first != last) { if (pred(*first)) *d_first++ = *first; first++; } return d_first;}
阅读全文
0 0
- Effective STL学习笔记-条款36
- 【Effective STL】条款1-5学习笔记
- 【Effective STL】条款6-12学习笔记
- 【Effective STL】条款13-18学习笔记
- Effective STL学习笔记-条款1
- Effective STL学习笔记-条款7
- Effective STL学习笔记-条款8-9
- Effective STL学习笔记-条款13|14
- Effective STL学习笔记-条款19
- Effective STL学习笔记-条款20
- Effective STL学习笔记-条款21
- Effective STL学习笔记-条款23
- Effective STL学习笔记-条款24
- Effective STL学习笔记-条款30
- Effective STL学习笔记-条款31
- Effective STL学习笔记-条款32
- Effective STL学习笔记-条款33
- Effective STL学习笔记-条款34
- 【Python基础】1.4.6 Turtle实例——用Python作画(1)
- query EasyUI tree 加载远程数据 java实现
- 一、细说Animation五大基本动画
- 现代操作系统学习(1)———引论
- Bootstrap常用设计样例
- Effective STL学习笔记-条款36
- css布局实现:左侧固定,右侧占满剩余的全部
- oracle中sys用户和system用户的区别
- sticky效果实现思路
- 修改PUBLIC 网卡子网掩码导致RAC的 VIP/SCAN IP的解决方法
- .NET Micro Framework介绍
- 解决Android系统L2TP/IPsec VPN无法使用
- Android 刷新加载框架
- leetcode 189-Rotate Array