c++ (适配器 && 取反)

取反适配器

#include <vector>
#include <algorithm>
#include <functional>
class findDafive :public unary_function<int,bool>
{
public:
	bool operator()(int val) const
	{
		return val>5;
	}
};
//取反适配器
void test02()
{
	//一元取反
	vector<int> v;
	for (int i = 0; i < 10; i++)
		v.push_back(i);
	//查找大于5的数
	//需求改为 找小于5的数
	auto it = find_if(v.begin(), v.end(), not1(findDafive()));
	//高端操作
	auto it = find_if(v.begin(), v.end(), not1(bind2nd(greater<int>(),5)));
	if (it != v.end())
		cout << *it << endl;
}

posted on 2021-04-29 11:26  lodger47  阅读(163)  评论(0)    收藏  举报

导航