c++ 内建函数对象

#include <iostream>

#include <string>

#include <fstream>

#include <vector>

#include <algorithm>

#include <deque>

#include <stack>

#include <queue>

#include <list>

#include <set>

#include <map>

#include <functional>

using namespace std;

void test()

{

negate<int> n;

cout << n(10) << endl; // 输出 -10

}

void test2()

{

plus<int> p;

cout << p(10, 20) << endl;

}

class MyCompare

{

public:

bool operator()(int a, int b)const

{

return a > b;

}

};

void test3()

{

vector<int> v;

v.push_back(10);

v.push_back(30);

v.push_back(20);

for(vector<int>::iterator i = v.begin(); i != v.end(); i++)

{

cout << *i << " ";

}

cout<< endl;

//sort(v.begin(), v.end() , MyCompare());

sort(v.begin(), v.end(), greater<int>());

for(vector<int>::iterator i = v.begin(); i != v.end(); i++)

{

cout << *i << " ";

}

}

void test4()

{

vector<bool> v;

v.push_back(true);

v.push_back(false);

v.push_back(true);

for(vector<bool>::iterator i = v.begin(); i != v.end(); i++)

{

cout << *i << " ";

}

cout<< endl;

vector<bool>v2;

v2.resize(v.size());

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

for(vector<bool>::iterator i = v2.begin(); i != v2.end(); i++)

{

cout << *i << " ";

}

}

int main()

{

test();

test2();

test3();

test4();

return 0;

system("pause");

}

相关推荐
椰猫子20 分钟前
Javaweb(Filter、Listener、AJAX、JSON)
java·开发语言
j_xxx404_35 分钟前
C++算法:哈希表(简介|两数之和|判断是否互为字符重排)
数据结构·c++·算法·leetcode·蓝桥杯·力扣·散列表
盛世宏博北京1 小时前
以太网温湿度传感器运维技巧,提升设备稳定性与使用寿命
开发语言·php·以太网温湿度传感器
Aaron15881 小时前
RFSOC+VU13P+RK3588的核心优势与应用场景分析
嵌入式硬件·算法·matlab·fpga开发·信息与通信·信号处理·基带工程
代码改善世界1 小时前
【MATLAB初阶】矩阵操作(一)
开发语言·matlab·矩阵
覆东流1 小时前
第1天:Python环境搭建 & 第一个程序
开发语言·后端·python
优家数科1 小时前
精准预测:基于多维用水量的滤芯寿命预警算法
算法
脱氧核糖核酸__1 小时前
LeetCode热题100——189.轮转数组(题解+答案+要点)
数据结构·c++·算法·leetcode
贾斯汀玛尔斯2 小时前
每天学一个算法-快速排序(Quick Sort)
数据结构·算法
炽烈小老头2 小时前
【每天学习一点算法 2026/04/16】逆波兰表达式求值
学习·算法