STL的bind1st,bind2nd,mem_fun,mem_fun_ref使用示例
2011-02-09 11:31
579 查看
// STL的bind1st,bind2nd,mem_fun,mem_fun_ref使用示例
// VC2008
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <functional>
int Sub(int x, int y)
{
return x-y;
}
class Add
{
public:
int add100(int x)
{
return x + 100;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "100-200 = " << (std::bind1st(std::ptr_fun(Sub), 100))(200) << std::endl;
std::cout << "200-100 = " << (std::bind2nd(std::ptr_fun(Sub), 100))(200) << std::endl;
Add add;
std::cout << "200+100 = " << (std::mem_fun(&Add::add100))(&add, 200) << std::endl;
std::cout << "200+100 = " << (std::mem_fun_ref(&Add::add100))(add, 200) << std::endl;
return 0;
}
// VC2008
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <functional>
int Sub(int x, int y)
{
return x-y;
}
class Add
{
public:
int add100(int x)
{
return x + 100;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "100-200 = " << (std::bind1st(std::ptr_fun(Sub), 100))(200) << std::endl;
std::cout << "200-100 = " << (std::bind2nd(std::ptr_fun(Sub), 100))(200) << std::endl;
Add add;
std::cout << "200+100 = " << (std::mem_fun(&Add::add100))(&add, 200) << std::endl;
std::cout << "200+100 = " << (std::mem_fun_ref(&Add::add100))(add, 200) << std::endl;
return 0;
}
相关文章推荐
- 【STL】函数 for_each; bind1st和bind2nd,not1; mem_fun和mem_fun_ref;
- bind1st, bind2nd, mem_fun, mem_fun_ref,这三个函数的使用
- C++之STL(九):函数适配器bind2nd 、mem_fun_ref 源码分析、函数适配器应用举例
- 从零开始学C++之STL(九):函数适配器bind2nd 、mem_fun_ref 源码分析、函数适配器应用举例
- 从零开始学C++之STL(九):函数适配器bind2nd 、mem_fun_ref 源码分析、函数适配器应用举例
- STL(九):函数适配器bind2nd 、mem_fun_ref 源码分析、函数适配器应用举例
- Stl中使类成员函数成为谓词,mem_fun 和mem_fun_ref的使用
- 了解使用ptr_fun、mem_fun和mem_fun_ref的原因1(Effective stl 条款41)
- STL中mem_fun和mem_fun_ref的用法 收藏
- ptr_fun,mem_fun,mem_fun_ref的使用
- STL 中 mem_fun 和 mem_fun_ref 的用法
- STL中mem_fun和mem_fun_ref的用法
- STL中mem_fun和mem_fun_ref的用法及区别
- 了解使用ptr_fun、mem_fun和mem_fun_ref的原因2(Effective stl 条款41)
- STL中mem_fun和mem_fun_ref的用法
- STL中仿函数(functors)、类成员和mem_fun的使用
- STL中mem_fun和mem_fun_ref的用法
- STL中仿函数(functors)、类成员和mem_fun的使用
- STL中mem_fun和mem_fun_ref的用法
- 【mem_fun/mem_fun_ref】成员函数作为函数对象使用