逻辑仿函数-非

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

class Print
{
public:
   void operator()(bool b)
   {
      cout << b << endl;
   }
};

int main()
{
   vector<bool> v;
   v.push_back(true);
   v.push_back(false);
   v.push_back(true);

   vector<bool> v2;
   v2.resize(v.size());

   transform(v.begin(), v.end(), v2.begin(), logical_not<bool>());
   for_each(v2.begin(), v2.end(), Print());

   return 0;
}
$ ./a.out 
0
1
0
posted @ 2022-07-31 11:42  thomas_blog  阅读(13)  评论(0编辑  收藏  举报