bind

#include <boost/config.hpp>
#include <boost/bind.hpp>
#include <iostream>
#include <vector>
#include <algorithm>

template<class T>
inline T & ToRef( T *pT)
{
 return *pT;
}
#define TODEF(x) bind( ToRef<x>, _1)

template<class T>
inline void DeletePointer( T *pT)
{
 delete pT;
}
#define ALL(v) (v).begin(), (v).end()

struct X
{
public:
 int m_t;
 X():m_t(11)
 {
 }
 
    bool f(int a)
 {
  std::cout << m_t << std::endl;
  return true;
 }
};

int main()
{
    using namespace boost;
 using namespace std;
 
 vector<X *> v;
 for( int i=0; i<10; ++i)
  v.push_back( new X);
 
 for_each( ALL(v), bind(&X::f, TODEF(X), 4 ) );
 
 for_each( ALL(v), bind( DeletePointer<X>, _1) );
 
 return 0;
}

 

posted on 2007-09-23 17:09 daiyie 阅读(212) 评论(1)  编辑  收藏

评论

# re: bind 2007-09-28 16:27 千里冰封

来点中文注释吧  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2007年9月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

统计

常用链接

留言簿(1)

随笔档案

收藏夹

搜索

最新评论

阅读排行榜

评论排行榜