#include <algorithm> #include <iostream> #include <functional> #include <vector> #include <numeric> #include <array> #include <cstring> #include <cstdio> #include <functional>//包装头文件 using namespace std; using namespace std::function; void go() { cout << "go" << endl; } int add(int a, int b) { return a + b; } int main() { //返回值 参数 function<void(void)> fun1 = go; fun1(); function<int(int, int)> fun2 = add; cout << fun2(10,19) << endl; function<int(int, int)> fun3 = [](int a, int b)->int{return a + b; }; cout << fun4(10, 19) << endl; }
Template meta accelerate
#include <algorithm> #include <iostream> #include <functional> #include <vector> #include <numeric> #include <array> #include <cstring> #include <cstdio> #include <functional>//包装头文件 using namespace std; int get50(int n) { if (n==1) { return 1; } else if (n==2) { return 2; } The else { return get50 (N- . 1 ) + get50 (N- 2 ); } } // template elements for implementing recursive acceleration recursive: repeatedly call waiting function, returns, waste of time more // fast execution , slow compile time, the code will be submitted to increase // the run time savings at compile time, recursively acceleration, optimization of the game, using only currently ++. 11 C Template < int N> struct Data { enum { RES Data = <N - . 1 > :: Data + RES <N - 2 > :: RES }; }; Template <> struct Data < . 1 > { enum { RES = . 1 }; }; Template <> struct Data < 2 > { enum { RES = 2 }; }; int main () { COUT << Data < 40 > :: RES << endl; // template element with to accelerate the processing code, only supports literals, constants, variables are not supported COUT << get50 ( 40 ) << endl; // very slow System ( " PAUSE " ); }