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

}

相关推荐
blasit4 小时前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
AI软著研究员5 小时前
程序员必看:软著不是“面子工程”,是代码的“法律保险”
算法
FunnySaltyFish5 小时前
什么?Compose 把 GapBuffer 换成了 LinkBuffer?
算法·kotlin·android jetpack
颜酱6 小时前
理解二叉树最近公共祖先(LCA):从基础到变种解析
javascript·后端·算法
地平线开发者1 天前
SparseDrive 模型导出与性能优化实战
算法·自动驾驶
董董灿是个攻城狮1 天前
大模型连载2:初步认识 tokenizer 的过程
算法
地平线开发者1 天前
地平线 VP 接口工程实践(一):hbVPRoiResize 接口功能、使用约束与典型问题总结
算法·自动驾驶
罗西的思考1 天前
AI Agent框架探秘:拆解 OpenHands(10)--- Runtime
人工智能·算法·机器学习
HXhlx1 天前
CART决策树基本原理
算法·机器学习
Wect1 天前
LeetCode 210. 课程表 II 题解:Kahn算法+DFS 双解法精讲
前端·算法·typescript