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 閱讀(229) 評論(1)  編輯  收藏

          評論

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

          來點中文注釋吧  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

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

          統計

          常用鏈接

          留言簿(1)

          隨筆檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 鄂伦春自治旗| 澄迈县| 克拉玛依市| 公安县| 大关县| 兖州市| 钟祥市| 自治县| 崇文区| 富裕县| 汕头市| 澄江县| 古浪县| 石嘴山市| 运城市| 饶阳县| 柞水县| 永州市| 巴东县| 石台县| 农安县| 会泽县| 金乡县| 遵化市| 怀集县| 南昌县| 秦安县| 浙江省| 额敏县| 苍山县| 阿图什市| 金沙县| 藁城市| 西充县| 三江| 肇州县| 潍坊市| 三门峡市| 彭水| 白水县| 和硕县|