没事,常学习。。啦啦啦
/*
*@vs2015 update3
*
*/
#include "stdafx.h"
#include <functional>
#include <vector>
#include <algorithm>
#include <iostream>
//判断一个容器中,大于5,小于10的个数
int main()
{
std::vector<int> collect = {1,3,2,5,8};
auto f = std::bind(std::logical_and<bool>(),
std::bind(std::greater<int>(),
std::placeholders::_1, 5),
std::bind(std::less_equal<int>(),
std::placeholders::_1, 10));
int count = std::count_if(collect.begin(), collect.end(), f);
std::cout << count << std::endl;
[&collect]() {
int count = 0;
for (auto iter = collect.begin(); iter != collect.end(); ++iter)
{
if (*iter > 5 && (*iter < 10))
{
count++;
}
}
std::cout << "number: " << count << std::endl;
}();
getchar();
return 0;
}