Erase–remove idiom
来源:互联网 发布:西蒙斯大学数据 编辑:程序博客网 时间:2024/06/02 02:55
// Use g++ -std=c++11 or clang++ -std=c++11 to compile.#include <vector> // the general-purpose vector container#include <iostream>#include <algorithm> // remove and remove_if bool is_odd(int i){ return (i % 2) != 0; }void print(const std::vector<int> &vec){ for (const auto& i: vec) std::cout << i << ' '; std::cout << std::endl;} int main(){ // initialises a vector that holds the numbers from 0-9. std::vector<int> v = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; print(v); // removes all elements with the value 5 v.erase( std::remove( v.begin(), v.end(), 5 ), v.end() ); print(v); // removes all odd numbers v.erase( std::remove_if(v.begin(), v.end(), is_odd), v.end() ); print(v); return 0; }/*Output:0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 6 7 8 9 0 2 4 6 8 */
阅读全文
0 0
- Erase–remove idiom
- remove&erase
- remove() and erase()
- Erase-remove惯用法
- STL-remove,erase
- Erase-remove惯用法
- STL remove和erase
- erase和remove
- erase() 和 remove()
- STL之erase,remove
- STL remove和erase
- Erase-remove 惯用法
- STL remove和erase
- STL remove和erase
- STL remove和erase
- stl remove 和 erase
- c++ remove() erase() 区别
- erase和remove区别
- B1015/A1062 . 德才论 (25)
- oracle创建存储过程定时任务时报错的问题
- linux 某个文件夹执行命令完全卡死完美解决方法
- java 异常处理
- 动态代理总结
- Erase–remove idiom
- hdu-1232 畅通工程(并查集)
- SEO香波Web病毒处理过程实录
- TIL使用alias选择PYTHON版本
- Struts2 没有对应属性异常 ognl.NoSuchPropertyException
- 结构体指针
- java将数据库里的数据导出到excel
- 理解RESTful架构
- 苹果iOS系统最新市占率统计:iOS 11份额达到52%