函数对象适配器之ptr_fun的使用示例

 1 //============================================================================
 2 // Name        : CopyInts4.cpp
 3 // Author      : motein
 4 // Version     :
 5 // Copyright   : Your copyright notice
 6 // Description : Hello World in C++, Ansi-style
 7 //============================================================================
 8 
 9 #include <iostream>
10 #include <algorithm>
11 #include <vector>
12 using namespace std;
13 
14 int u_func(int a)
15 {
16     int ret = a;
17     return ret;
18 }
19 
20 int b_func(int a,int b)
21 {
22     return a+b;
23 }
24 
25 void call()
26 {
27     pointer_to_unary_function<int,int> uf(u_func);
28     cout << uf(100) << endl;
29 
30     pointer_to_binary_function<int,int,int> bf(b_func);
31     cout << bf(111,222) << endl;
32 
33     cout << ptr_fun(u_func)(100) << endl;
34     cout << ptr_fun(b_func)(111,222) << endl;
35 
36 }
37 
38 int main()
39 {
40     call();
41     return 0;
42 }
原文地址:https://www.cnblogs.com/AmitX-moten/p/3712198.html