C++11 lambda函数符

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
const long Size1 = 39L;
const long Size2 = * Size1;
const long Size3 = * Size2;
bool f3(int x) {return x % == ;}
bool f13(int x) {return x % == ;} int main() {
using std::cout;
std::vector<int>numbers(Size1);
std::srand(std::time());
std::generate(numbers.begin(),numbers.end(),std::rand); cout << "sample size " << Size1 << std::endl;
int count3 = std::count_if(numbers.begin(),numbers.end(),f3);
cout << "count of numbers divisable by 3 " << count3 << std::endl; int count13 = std::count_if(numbers.begin(),numbers.end(),f13);
cout << "count of numbers divisable by 13" << count13 << std::endl; numbers.resize(Size2);
std::generate(numbers.begin(),numbers.end(),std::rand);
cout << "sample size" << Size2 << std::endl; class f_mod {
private :
int dv;
public :
f_mod(int d = ) : dv(d) { }
bool operator () (int x) { return x % dv == ; }
}; count3 = std::count_if(numbers.begin(),numbers.end(),f_mod());
cout << "count of number div by 13" << count3 << std::endl; numbers.resize(Size3);
std::generate(numbers.begin(),numbers.end(),std::rand);
cout << "sample size" << Size3 << std::endl;
count3 = std::count_if(numbers.begin(),numbers.end(),[](int x) {return x % == ; });
cout << "count3 = " << count3 << std::endl; return ;
}
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
const long Size = 390000L;
int main() {
using std::cout;
std::vector<int>numbers(Size);
std::srand(std::time());
std::generate(numbers.begin(),numbers.end(),std::rand);
cout << "sample size = " << Size << std::endl;
int count3 = std::count_if(numbers.begin(),numbers.end(),[](int x) {return x % == ;});
cout << "count of numbers div by 3 " << count3 << std::endl; int count13 = ;
std::for_each(numbers.begin(),numbers.end(),[&count13](int x) { count13 += x % == ; });
cout << " count 13 " << count13 << std::endl; count3 = count13 = ;
std::for_each(numbers.begin(),numbers.end(),[&] (int x) {count3 += x % == ; count13 += x % == ;});
cout << "count3 " << count3 << " count13 " << count13 << std::endl; return ;
}
上一篇:微服务理论之二:面向微服务架构与传统架构、SOA对比,以及云化对比


下一篇:[转帖]从 SOA 到微服务,企业分布式应用架构在云原生时代如何重塑?