首页 > 代码库 > stl之std::remove_copy
stl之std::remove_copy
template <class InputIterator, class OutputIterator, class T> OutputIterator remove_copy (InputIterator first, InputIterator last, OutputIterator result, const T& val);
说明:
Copies the elements in the range [first,last) to the range beginning at result, except those elements that compare equal to val.
对range进行遍历,除了==val的值,其他的copy到以result开始的位置
算法结果等价于
template <class InputIterator, class OutputIterator, class T> OutputIterator remove_copy (InputIterator first, InputIterator last, OutputIterator result, const T& val){ while (first!=last) { if (!(*first == val)) { *result = *first; ++result; } ++first; } return result;}
用例:
// remove_copy example#include <iostream> // std::cout#include <algorithm> // std::remove_copy#include <vector> // std::vectorint main () { int myints[] = {10,20,30,30,20,10,10,20}; // 10 20 30 30 20 10 10 20 std::vector<int> myvector (8); std::remove_copy (myints,myints+8,myvector.begin(),20); // 10 30 30 10 10 0 0 0 std::cout << "myvector contains:"; for (std::vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it) std::cout << ‘ ‘ << *it; std::cout << ‘\n‘; return 0;}
原文链接:http://www.cplusplus.com/reference/algorithm/remove_copy/
stl之std::remove_copy
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。