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

}

相关推荐
子琦啊9 小时前
【算法复习】哈希|Map 与 Set 两个高频套路
算法·哈希算法
接着奏乐接着舞9 小时前
java lambda表达式
java·开发语言·python
IT搬砖客9 小时前
CC2340从机开发入门之OAD例程的选择
c语言·开发语言·单片机·嵌入式硬件
Alaso_shuang9 小时前
视觉组通识
数码相机·算法·计算机视觉
ch.ju9 小时前
Java程序设计(第3版)第四章——成员方法
java·开发语言
纽扣6679 小时前
【算法进阶之路】链表终极进阶:合并 K 个有序链表 + 复制带随机指针的链表(含双解法)
数据结构·算法·链表
marsh02069 小时前
53 openclaw插件市场:开发与发布自己的插件
开发语言·前端·javascript
牙牙学语的阿猿9 小时前
sentinel创建规则时的坑
java·开发语言·sentinel
fai厅的秃头姐!9 小时前
2586. 统计范围内的元音字符串数
开发语言·c#
超梦dasgg9 小时前
Java 生产环境 JVM 调优实战
java·开发语言·jvm