美文网首页
6.逻辑仿函数

6.逻辑仿函数

作者: lxr_ | 来源:发表于2021-04-28 10:10 被阅读0次
    #include<iostream>
    using namespace std;
    
    #include<vector>
    #include<functional>
    #include<algorithm>
    
    //函数原型
    //template<class T> bool logical_and<T> 逻辑与
    //template<class T> bool logical_or<T> 逻辑或
    //template<class T> bool logical_not<T> 逻辑非
    
    void test0601()
    {
        vector<bool> v;
    
        v.push_back(true);
        v.push_back(false);
        v.push_back(true);
        v.push_back(false);
    
        for (vector<bool>::iterator it = v.begin(); it != v.end(); it++)
        {
            cout << (*it) << " ";
        }
        cout << endl;
    
        //利用逻辑非操作将容器v搬运到容器v2中,并执行取反操作
    
        vector<bool> v2;
    
        v2.resize(v.size());//先指定大小,再进行搬运
    
        transform(v.begin(), v.end(), v2.begin(), logical_not<bool>());//搬运的同时做取反操作
    
        for (vector<bool>::iterator it = v2.begin(); it != v2.end(); it++)
        {
            cout << (*it) << " ";
        }
        cout << endl;
    
    }
    int main()
    {
        test0601();
    
        system("pause");
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:6.逻辑仿函数

          本文链接:https://www.haomeiwen.com/subject/vzdjrltx.html