C++仿函数之逻辑仿函数

tech2026-08-27  3

逻辑仿函数

功能描述:

实现逻辑运算 #include <iostream> #include <vector> #include <functional> #include <algorithm> using namespace std; void test01() { 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 << endl; } 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 << endl; } cout << endl; } int main() { test01(); return 0; }
最新回复(0)