zoukankan      html  css  js  c++  java
  • erase & remove_if 合用

      words_.erase(
          remove_if(
              words_.begin(),
              words_.end(),
              [&](const entry& e) {
                return (e.type == entry_type::word && e.count < t) ||
                    (e.type == entry_type::label && e.count < tl);
              }),
          words_.end());
    words_ : vector
    remove_if: 返回的是迭代器
    // remove_if example
    #include <iostream>     // std::cout
    #include <algorithm>    // std::remove_if
    
    bool IsOdd (int i) { return ((i%2)==1); }
    
    int main () {
      int myints[] = {1,2,3,4,5,6,7,8,9};            // 1 2 3 4 5 6 7 8 9
    
      // bounds of range:
      int* pbegin = myints;                          // ^
      int* pend = myints+sizeof(myints)/sizeof(int); // ^                 ^
    
      pend = std::remove_if (pbegin, pend, IsOdd);   // 2 4 6 8 ? ? ? ? ?
                                                     // ^       ^
      std::cout << "the range contains:";
      for (int* p=pbegin; p!=pend; ++p)
        std::cout << ' ' << *p;
      std::cout << '
    ';
    
      return 0;
    }

    Lambda 函数与表达式

    [&]     // 任何被使用到的外部变量都隐式地以引用方式加以引用。
     
     
  • 相关阅读:
    odoo10 入门
    git 命令详细介绍
    odoo中Python实现小写金额转换为大写金额
    {DARK CTF } OSINT/Eye
    2020 12 18
    2020 12 17
    2020 12 16
    2020 12 15
    2020 11 14
    2020 11 13
  • 原文地址:https://www.cnblogs.com/TMatrix52/p/11305883.html
Copyright © 2011-2022 走看看