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. GridView .net访问

    HTML code <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns=&qu ...

  2. 使用Git(msysgit)和TortoiseGit上传代码到GitHub

    1.准备 下载Git for Windows (msysgit) 下载TortoiseGit 安装过程很简单,一直点击下一步到完成即可. 2.配置TortoiseGit 1.双击TortoiseGit ...

  3. [转]最全Redis面试题整理

    此为转载文章,仅做记录使用,方便日后查看,原文链接:http://www.bieryun.com/3405.html 1.什么是Redis? 答:Redis全称为:Remote Dictionary ...

  4. mysql五:pymysql模块

    一.介绍 之前都是通过MySQ自带的命令行客户端工具Mysql来操作数据库,那如何在Python程序中操作数据库呢?这就需要用到pymysql模块了. 这个模块本质就是一个套接字客户端软件,使用前需要 ...

  5. ECMAScript 6简介

    一.起步 1.扎实的HTML/CSS/Javascript基本功,这是前置条件. 2.不要用任何的构建项目工具,只用最简单的<script>,把教程里的例子模仿一遍,理解用法.不推荐上来就 ...

  6. CKEditor的使用

    需要配置的功能列表 //class: cke_button( 按钮 ) , ck_combo(下拉) /* 需要配置的功能列表 document:保存(save).新建(newpage).预览(pre ...

  7. android drag

    1.Android:Drag and Drop的应用 2.Android 用户界面---拖放(Drag and Drop)(三) 3.Android 用户界面---拖放(Drag and Drop)( ...

  8. Qt删除文件夹

    写的软件需要进行文件夹的复制,开始不怎么懂就找了个拷贝文件夹的代码测试了一下,运行程序选择了源目录和目标目录相同进行拷贝,结果悲剧了.因为是递归拷贝,导致文件夹被嵌套N层,软件死机,强制结束后,产生的 ...

  9. matlab练习程序(模糊集图像增强)

    算法有很多变种.不过主要就是以下三步. 1.设计隶属度函数将图像从空间域变换到模糊集域. 2.设计模糊增强算子,在模糊集域对图像进行处理. 3.根据第1步的隶属度函数重新将图像从模糊集域变换到空间域. ...

  10. java面试题全集(上)--java基础

    本文转载自:https://blog.csdn.net/jackfrued/article/details/44921941 1.面向对象的特征有哪些方面? 答:面向对象的特征主要有以下几个方面: - ...