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)

          隨筆檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 铁岭县| 台江县| 大同县| 宁津县| 剑阁县| 岢岚县| 巴南区| 长春市| 家居| 高平市| 铜鼓县| 崇左市| 玛纳斯县| 长汀县| 凌源市| 本溪市| 高唐县| 海城市| 宁河县| 和政县| 塔城市| 沐川县| 阳谷县| 杭州市| 巧家县| 濮阳市| 吉林省| 大荔县| 资溪县| 剑河县| 桦南县| 信宜市| 延寿县| 青神县| 永昌县| 鹰潭市| 炎陵县| 江津市| 平武县| 凤凰县| 南丹县|