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::vector int main () {
int myints[] = {,,,,,,,}; // 10 20 30 30 20 10 10 20
std::vector<int> myvector (); std::remove_copy (myints,myints+,myvector.begin(),); // 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 ;
}

原文链接:http://www.cplusplus.com/reference/algorithm/remove_copy/

 

stl之std::remove_copy的更多相关文章

  1. STL的std::find和std::find_if

    std::find是用来查找容器元素算法,但是它只能查找容器元素为基本数据类型,如果想要查找类类型,应该使用find_if. 小例子: #include "stdafx.h" #i ...

  2. STL之std::set、std::map的lower_bound和upper_bound函数使用说明

    由于在使用std::map时感觉lower_bound和upper_bound函数了解不多,这里整理并记录下相关用法及功能. STL的map.multimap.set.multiset都有三个比较特殊 ...

  3. C++ STL:std::unorderd_map 物理结构详解

    拉链法的 unordered_map 和你想象中的不一样 根据数组+拉链法的描述,我们很快能想到下面这样的拉链法实现的哈希表,但真的是这样吗?一起看下源码里的实现是怎么样的. 深入STL源码 代码不会 ...

  4. c++ stl algorithm: std::fill, std::fill_n

    std::fill 在[first, last)范围内填充值 #include <iostream> #include <vector> #include <algori ...

  5. c++ stl algorithm: std::find, std::find_if

    std::find: 查找容器元素, find仅仅能查找容器元素为<基本数据类型> [cpp] view plaincopy #include <iostream> #incl ...

  6. STL源代码分析——STL算法remove删除算法

    前言 因为在前文的<STL算法剖析>中,源代码剖析许多.不方便学习,也不方便以后复习,这里把这些算法进行归类.对他们单独的源代码剖析进行解说.本文介绍的STL算法中的remove删除算法. ...

  7. STL源代码剖析——STL算法stl_algo.h

    前言 在前面的博文中剖析了STL的数值算法.基本算法和set集合算法.本文剖析STL其它的算法,比如排序算法.合并算法.查找算法等等.在剖析的时候.会针对函数给出一些样例说明函数的使用.源代码出自SG ...

  8. 将三维空间的点按照座标排序(兼谈为std::sort写compare function的注意事项)

    最近碰到这样一个问题:我们从文件里读入了一组三维空间的点,其中有些点的X,Y,Z座标只存在微小的差别,远小于我们后续数据处理的精度,可以认为它们是重复的.所以我们要把这些重复的点去掉.因为数据量不大, ...

  9. DLL中传递STL参数(如Vector或者list等)会遇到的问题[转载]

    最近的一个项目中遇到了调用别人的sdk接口(dll库)而传给我的是一个vector指针,用完之后还要我来删除的情况.这个过程中首先就是在我的exe中将其vector指针转为相应指针再获取vector中 ...

随机推荐

  1. 深入理解JavaScript系列(34):设计模式之命令模式

    介绍 命令模式(Command)的定义是:用于将一个请求封装成一个对象,从而使你可用不同的请求对客户进行参数化:对请求排队或者记录请求日志,以及执行可撤销的操作.也就是说改模式旨在将函数的调用.请求和 ...

  2. What's the difference between @Component, @Repository & @Service annotations in Spring?

    @Component is equivalent to <bean> @Service, @Controller , @Repository = {@Component + some mo ...

  3. 重构指南 - 尽快返回(Return ASAP )

    尽快返回就是如果方法中的条件判断可以得到结果,则尽快返回该结果. 1. 检查条件,如果不满足就立即返回,不执行下面的逻辑. 2. 当包含大量的if else嵌套,代码可读性变差,也容易出现异常. 3. ...

  4. 运行jsp时,报错404

    The origin server did not find a current reprsentation for the target resource or is not willing to ...

  5. Java开发坏境配置

    在"系统变量"中设置3项属性,JAVA_HOME,PATH,CLASSPATH(大小写无所谓),若已存在则点击"编辑",不存在则点击"新建" ...

  6. css滤镜模糊效果filter和backdrop-filter

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. python数据分析工具安装集合

    用python做数据分析离不开几个好的轮子(或称为科学棧/第三方包等),比如matplotlib,numpy, scipy, pandas, scikit-learn, gensim等,这些包的功能强 ...

  8. envi利用矢量数据对影像做多边形裁剪 (转)

    2011-05-25 17:31:10|  分类: ENVI|举报|字号 订阅 来自:http://zhangling357522.blog.163.com/blog/static/184687296 ...

  9. BIEE入门(二)物理层的定义

    使用BIEE的第一步是使用admintool去建立一个多维数据模型,而建立多维数据模型的第一步则是建立物理层,请注意因为BIEE本身并不存 储数据,所以所谓BIEE物理层的意义是需要在BIEE里建立各 ...

  10. C++ 数据库 char 转 wchar_t SQLWCHAR

    C++中对数据库的操作感觉太复杂了,不如C#好使,但最近出于某些原因还是学习了一下C++下操作数据库的方法. 如果要想用C++实现对数据库的操作其实很简单,但是如果你需要动态的操作数据库(比如获得用户 ...