1 #include <iostream> 2 #include <functional> 3 #include <vector> 4 #include <algorithm> 5 #include <numeric> 6 using namespace std; 7 using namespace std::placeholders; 8 9 class myclass 10 { 11 public: 12 int get(int data) 13 { 14 return data % 2; 15 } 16 }; 17 18 void main() 19 { 20 //创建容器 21 vector<int> myint{ 1,2,3,4,5,6,7,8,9,10 }; 22 //逐个数据进行判断是否满足lambda表达式 23 int num = count_if(myint.begin(), myint.end(), [](int data)->bool {return data % 2 == 0; }); 24 cout << num << endl; 25 myclass my1; 26 auto fun = bind(&myclass::get, &my1, _1); 27 num = count_if(myint.begin(), myint.end(), [](int data)->bool {return data % 2 == 0; }); 28 cout << num << endl; 29 cin.get(); 30 }