zoukankan      html  css  js  c++  java
  • 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::vector
    
    int 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 << '
    ';
    
      return 0;
    }

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

     
  • 相关阅读:
    JS在文本框光标处插入文本
    nodejs.exe版安装
    JS实现移动层
    JS实现日历
    Ajax相关
    机器学习 目录
    Butterfly 主题魔改记录
    《机器学习》西瓜书习题 第 6 章
    numpy 中判断某字符串 array 是否含有子字符串
    《机器学习》西瓜书习题 第 5 章
  • 原文地址:https://www.cnblogs.com/xkxjy/p/4204903.html
Copyright © 2011-2022 走看看