• 没有结束,STL才刚刚开始


    这样一个题目,鼓励自己!

    学习了两天STL的基本语法(看了那本30分钟学会STL),对标准模版库有了一个广义上的认识。

    STL向我们提供了三项功能:

    仅仅学习了几个函数,放到这里。给自己做笔记。

    for_each

    template<class InputIterator, class Function>

      Function for_each(InputIterator first, InputIterator last, Function f)

      {

        for ( ; first!=last; ++first ) f(*first);

        return f;

      }

     

    find_if

    template<class InputIterator, class Predicate>

      InputIterator find_if ( InputIterator first, InputIterator last, Predicate pred )

      {

        for ( ; first!=last ; first++ ) if ( pred(*first) ) break;

        return first;

      }

    用第三个函数(以前两个为参数)处理fist

     

    accumulate()

    template <class InputIterator, class T>

       T accumulate ( InputIterator first, InputIterator last, T init )

    {

    while ( first!=last )

        init = init + *first++;  // or: init=binary_op(init,*first++) for the binary_op version

      return init;}

     

     

     

    发生器函数对象

     

    绑定器函数对象

     

    int k=count_if(aList.begin(),aList.end(),bind2nd(greater<int>(),8));

    bind1st 绑定函数第一个参数

    bind2nd 绑定参数为第二个参数

     

    副两个程序,简单看看(新手)http://115.com/file/c28h19w2

    30分钟学会STL:http://115.com/file/anwgxcbc#


    作者:leisure
    原文出自:http://www.cnblogs.com/leisure/
    感谢园子,感谢各位支持。本文版权归伟征和博客园共有,欢迎转载@ 但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    只是想分享,欢迎拍砖!促进我成长

  • 相关阅读:
    python 序列化
    python 文件目录操作
    正则表达式 贪婪与非贪婪
    python StringIO&BytesIO
    正则表达式 1
    了解HTML表单之input元素的23种type类型
    JS数组reduce()方法详解及高级技巧
    react之组件的shouldcomponentUpdate使用&&Component与PureComponent
    react之setState面试题
    react之setState异步和同步问题
  • 原文地址:https://www.cnblogs.com/leisure/p/2398597.html
Copyright © 2020-2023  润新知