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");

}

相关推荐
薛不痒几秒前
大模型agent
java·开发语言
计算机安禾1 分钟前
【数据结构与算法】第1篇:为什么要学习数据结构与算法?专栏导学
c语言·开发语言·c++·学习·算法·visual studio code·visual studio
言之。1 分钟前
时间轮(Time Wheel)数据结构入门指南
开发语言·数据结构·python
左左右右左右摇晃2 分钟前
Java并发——CAS(比较并替换)
java·开发语言·jvm
IronMurphy7 分钟前
【算法三十】124. 二叉树中的最大路径和
算法·深度优先
Yang-Never8 分钟前
AI Code -> Windows电脑安装Claude
开发语言·windows·git
TechPioneer_lp10 分钟前
腾讯测试开发岗位 LeetCode 高频题汇总(2026版)
数据结构·算法·大厂笔试·leetcode高频题·腾讯测试开发·大厂校招·大厂春招
REDcker11 分钟前
libevent、libev 与 libuv:对比、演进与实现原理
linux·c++·后端·编程·c·高并发·服务端
551只玄猫13 分钟前
【操作系统原理 实验报告6】磁盘调度算法
算法·操作系统·os·实验报告·操作系统原理·磁盘调度算法·磁盘调度
天下无敌笨笨熊14 分钟前
C#异步开发探微
开发语言·c#