zoukankan      html  css  js  c++  java
  • transform、for_each

    transform

      与for_each类似可搭配function object对range内的元素进行操作,但for_each不关心function object的返回值,但transform会把操作后的range输出到另一个range,可以被就地来更改序列,允许first和result相等,但outputIterator result不可与first和last中的任何一个inputIterator相同

    //版本一:UnaryFunction作用于input range上, 
    template <class InputerIterator,class OutputIterator,class UnaryFunction>
    OutputIterator transform(InputerIterator first,InputerIterator last,OutputIterator result,UnaryFunction cmp);
    
    //版本二:第一个range对应的i1和第二个range对应的i2,cmp(*i1,*i2)后赋值给result 
    template <class InputerIterator1,class InputerIterator2,class OutputIterator,class BinaryFunction>
    OutputIterator transform(InputerIterator first1,InputerIterator last1,
                             InputerIterator2 first2,first2OutputIterator result,BinaryFunction cmp);

    for_each

      将函数f施加于区间[first,last)的每一个元素身上。

    template<class InputIterator, class Function>
    Function for_each(InputIterator first, InputIterator last, Function f)
    {
        for ( ; first!=last; ++first ) f(*first);
        return f;
    }
  • 相关阅读:
    linux日志守护进程 syslog
    ORM(一)
    ajax
    python bbs项目代码分析
    jquery基础
    PHP根据概率产生随机数
    用PHP删除文件操作unlink
    实时显示剩余可以输入的文字数
    mysql分表方法实现
    php 输出昨天,今天,明天是星期几的方法
  • 原文地址:https://www.cnblogs.com/tianzeng/p/10403834.html
Copyright © 2011-2022 走看看