zoukankan      html  css  js  c++  java
  • 使用标准库函数对象的例子

    14.42 使用标准库函数对象及适配器定义一条表达式,令其

    1 统计打于1024的值有多少个。

    2 找到第一个不等于pooh的字符串

    3 将所有的值乘以2

    14.43 使用标准库函数对象判断一个给定的int值是否能被int容器中的所有元素整除

    #include<iostream>
    #include<functional>
    #include<string>
    #include<vector>
    #include<algorithm>
    using namespace std;
    
    int main()
    {
        using namespace std::placeholders;
        vector<int> vec={3774,2,3,6,5,66666456,342,2,4212,43,245,5,345,43534,5345454};
        vector<string> vec1={"pooh","qpooh"};
        cout<<count_if(vec.begin(),vec.end(),bind(greater<int>(),_1,1024))<<endl;
        cout<<*find_if(vec1.begin(),vec1.end(),bind(not_equal_to<string>(),_1,"pooh"))<<endl;
        for_each(vec.begin(),vec.end(),bind(multiplies<int>(),_1,2));
        for_each(vec.begin(),vec.end(),[](int i){cout<<i<<" ";});
        cout<<endl;
        int n;
        cin>>n;
    
        if(find_if(vec.begin(),vec.end(),bind(modulus<int>(),_1,n))!=vec.end())
            cout<<"Not divisible"<<endl;
        else
            cout<<"divisible"<<endl;
        return 0;
    }
  • 相关阅读:
    C#创建线程
    Halcon算子
    二叉树的层次遍历
    反转单链表
    “开-闭”原则 (Open-Closed principle, OCP)
    CSUOJ1867 John and Health rate
    LOCAL_MODULE_TAGS
    void * kmalloc(size_t size, int flags)
    printk(Loglevels string)
    container_of宏定义解析
  • 原文地址:https://www.cnblogs.com/wuchanming/p/3941648.html
Copyright © 2011-2022 走看看