当前位置:网站首页>STL - inverter
STL - inverter
2022-06-28 08:42:00 【Jinky strange 18】
1. Inverter The role of : To the existing Function object Logic reverses
not1 to One yuan Function object Take the opposite
not2 to binary Function object Take the opposite
Let's learn more about the negator through a piece of code
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int arr[] = {12,34,42,52,64,62,90,102,46,256,78};
int len = sizeof(arr) / sizeof(arr[0]);
vector<int> vec(arr,arr+len);
// Use the binders provided by the system bind2nd and Inverter not1
vector<int>::iterator it1 = find_if(vec.begin(),vec.end(),bind2nd(greater<int>(),100));
if(it1 != vec.end())
{
cout << " first Greater than 100 The elements of :" << *it1 << endl;
}
vector<int>::iterator it2 = find_if(vec.begin(),vec.end(),not1(bind2nd(greater<int>(),100)));
if(it2 != vec.end())
{
cout << " first No Greater than 100 The elements of :" << *it2 << endl;
}
return 0;
}
Inverter : not1 The implementation is to negate the internal unary function object of the binder , Like before Greater than , Now it is Less than or equal to , That is, not more than
2. Inverter The concrete realization of :
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
using namespace std;
template<typename Fn>
class MyNote
{
public:
MyNote(Fn & f) :fn(f){}
bool operator()(const typename Fn::argument_type& val)// Unary function object argument_type
{
return !fn(val);
}
private:
Fn fn;
};
template<typename Fn>
MyNote<Fn> mynote(Fn f)
{
return MyNote<Fn>(f);
}
int main()
{
int arr[] = {12,34,42,52,64,62,90,102,46,256,78};
int len = sizeof(arr) / sizeof(arr[0]);
vector<int> vec(arr,arr+len);
vector<int>::iterator it = find_if(vec.begin(),vec.end(),mynote(bind2nd(greater<int>(),100)));
if(it != vec.end())
{
cout << " first No Greater than 100 The elements of :" << *it << endl;
}
return 0;
}

summary : The reverser can be seen as a supplement to the binder
边栏推荐
- Analysis of prepaid power purchase device
- High rise building fire prevention
- 使用transform:scale之后导致页面鼠标悬浮事件消失
- Robot Rapping Results Report
- TCP
- AVFrame内存管理api
- Mysql8.0 forgot the root password
- Maintenance and protection of common faults of asynchronous motor
- [learning notes] search
- Application of energy management system in iron and steel enterprises
猜你喜欢

Almost Union-Find(带权并查集)

爱分析发布《2022爱分析 · IT运维厂商全景报告》 安超云强势入选!

找合适的PMP机构只需2步搞定,一查二问

抖音服务器带宽有多大,才能供上亿人同时刷?

罗氏线圈可以测量的大电流和频率范围

Almost union find (weighted union search)

Discussion on the improvement and application of the prepayment system in the management of electricity charge and price

TCP那点事

webrtc优势与模块拆分

TCP
随机推荐
为什么函数模板没有偏特化?
Key points of building fire protection design
Loss loss function
广州:金融新活水 文企新机遇
利尔达低代码数据大屏,铲平数据应用开发门槛
Wasmedge 0.10.0 release! New plug-in extension mechanism, socket API enhancement, llvm 14 support
AI chief architect 8-aica-gao Xiang, in-depth understanding and practice of propeller 2.0
FatMouse and Cheese
Redis deployment under Linux & redis startup
[reprint] STM32 GPIO type
FatMouse and Cheese
Understanding of CUDA, cudnn and tensorrt
Potential safety hazards in elderly care facilities
yaml json
Loss损失函数
[learning notes] shortest path + spanning tree
Super Jumping! Jumping! Jumping!
How do individuals open accounts to speculate in stocks? Is online account opening safe?
Set the icon for the title section of the page
用Pytorch搭建第一個神經網絡且進行優化