• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            FireEmissary

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              14 隨筆 :: 0 文章 :: 20 評論 :: 0 Trackbacks

            #

            我正設計一個布局類,對于托管的對象自動計算更新后的布局位置后調用用戶的回調函數(shù).bind用得非常high,然后最后卻編譯不過.
            抽象出來就是如下代碼:
            #include <iostream>
            #include 
            <boost/bind.hpp>
            #include 
            <boost/function.hpp>
            class test1
            {
            public:
                template
            <typename S>
                
            double handle(S s)
                {
                    s(
            1);
                    std::cout
            <<"test1\n";
                    
            return 1;
                }
                template
            <typename F>
                
            void handle1(F f)    {
            boost::bind(
            &test1::handle<F>,this,f)();//這里
                }

            };
            class test2
            {
            public:
                
            double handle(int i)
                {
                    std::cout
            <<"test2\n";
                    
            return i;
                }
            };
            int _tmain(int argc, _TCHAR* argv[])
            {
                test2 t2;
                test1 t1;

                t1.handle1(boost::bind(
            &test2::handle,t2,_1));
                
            return 0;
            }
            原來,bind為了支持
            boost::bind(  std::logical_and<bool>(),     boost::bind(std::greater<int>(),_1,5),   boost::bind(std::less_equal<int>(),_1,10));
            這類操作,內部自動對bind_t(即bind的返回類型)調用取得結果來作參數(shù).代價就是不能把bind_t作為參數(shù)了.解決方法是,boost::ref包起來
            boost::bind(&test1::handle<F>,this,boost::ref(f))();

            boost user mail list有人建議
            boost::bind(&test1::handle<boost::_bi::protected_bind_t<F>
            >,this, protect(f))();
            不過我認為用戶還是別去接觸boost::_bi空間來的好


            另一件事是:bind返回的對象支持多于它本該支持的參數(shù).同樣上面的例子,改為
            boost::bind(&test1::handle<F>,this,boost::ref(f))(1,2,3,4,5);
            照樣編譯通過.帶來的好處就是像boost::asio這樣的庫接受的回調可以很靈活,你要不要boost::system::error_code,bytes_transferred都沒問題.asio::io_service總是壓入所有必須的參數(shù)來進行回調,而被bind后的回調對象會只抽取自己必須的參數(shù).

            posted @ 2011-03-16 12:56 FireEmissary 閱讀(3067) | 評論 (0)編輯 收藏

                 摘要: KMP 算法并非優(yōu)化 用于實際的字符串查找并不理想.要費勁心血實現(xiàn)和優(yōu)化它,才能在特定的字符串上略微超過(也可能略微遜過)std::search.
              閱讀全文
            posted @ 2010-07-01 21:34 FireEmissary 閱讀(4011) | 評論 (2)編輯 收藏

            3.0以后的opengl引入了廢棄模式和profile定義.其中core profile上下文不支持被廢棄的函數(shù).
            freeglut支持兼容模式指定:
            glutInitContextVersion指定版本
            glutInitContextFlags指定是否向后兼容.
            glutInitContextProfile指定profile是否core的.

            freeglut自帶的例子smooth_opengl3把glutInitContextVersion指定參數(shù)GLUT_FORWARD_COMPATIBLE,windows平臺映射到wgl的WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB標記.而WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB標記的意思是"向前"兼容,也就是說不支持廢棄的函數(shù).
            這樣smooth_opengl3編譯出來的例子出現(xiàn)gl錯誤,什么顯示都沒有.

            解決方案是注釋掉glutInitContextFlags調用,因為默認上下文就是以兼容模式建立.
            glutInitContextProfile請求opengl 3.2以上版本才有效果,通常可以不管它.
            posted @ 2010-06-20 18:21 FireEmissary 閱讀(1550) | 評論 (0)編輯 收藏

             

            經典的求公共子序列算法需要兩個序列的長度已知.而且通常用于計算字符串的公共子序列.

            我實現(xiàn)的算法針對原有的算法輸入需求解耦合,使得算法極度可適配.能用于字符串公共子序列計算和文件diff計算.理論上能用于任何具備相似特征的兩個序列的公共子序列計算.

            LCS_Calculate有三個變種:

             

            template<typename L_Iterator,typename R_Iterator,typename Container>

            LCS_Size FEtool::LCS_Calculate(L_Iterator lbeg,L_Iterator lend,  R_Iterator rbeg,R_Iterator rend,Container 
            &out);

            template
            <typename L_Iterator,typename R_Container,typename Container>

            inline LCS_Size FEtool::LCS_Calculate(L_Iterator lbeg,L_Iterator lend,  R_Container 
            const&rcontainer, Container &out);

            template
            <typename L_Container,typename R_Container,typename Container>

            inline LCS_Size FEtool::LCS_Calculate(L_Container 
            const& lcontainer,   R_Container const&rcontainer, Container &out);

            L_Iterator接受輸入迭代器. R_Iterator接受隨機迭代器. L_ContainerR_Container分別調用它們的begin()end()方法轉調用到LCS_Calculate的第一個版本.

            L_*打頭的指代比較序列中左邊那個,R_*打頭的指代比較序列中右邊那個.

            最后一個參數(shù)Container&out接收一個容器用來輸出序列各段相同的地方.典型的Container參數(shù)為std::deque<FEtool::SectionCommon> section;也可以為FEtool:: EmptyContainer.

            class EmptyContainer
            {
            public:
                
            void push_back(SectionCommon const&){};
                LCS_Size size()
            {return 0;}
                
            void clear(){}
            }
            ;


            如果為FEtool:: EmptyContainer參數(shù)則通過模板特化代碼選擇不計算兩段序列的相同部分。

             

            struct LCS_Compare_Trait
            {
            template
            <typename L,typename R>
            static   bool equal(L const& left, R const& right)
                    
            {
                        
            return left==right;
                    }

            }
            ;

            定義了比較算法,默認用operator==.你可以在FEtool空間通過特化或偏特化LCS_Compare_Trait:: equal來定制它.

             

            struct SectionCommon
            {
                LCS_Size L_begin;
                LCS_Size R_begin;
                LCS_Size count;
                
            void clear(){L_begin=0;R_begin=0;count=0;}
            }
            ;

            指示兩個序列的相同部分. 比如SectionCommon:: L_begin0, SectionCommon:: R_begin10, SectionCommon::count5.就表示左邊序列從0開始的5個數(shù)據(jù),和右邊序列從10開始的5個數(shù)據(jù)都相同.

             

            LCS_Calculate內部根據(jù)傳入?yún)?shù)優(yōu)化實現(xiàn).經過對經典的動態(tài)規(guī)劃解公共子序列算法的考察發(fā)現(xiàn),外圍那個循環(huán)只需要遍歷它代表的序列一次;即左邊序列則滿足輸入迭代器即可.它要求右邊序列始終是傳入隨機迭代器.內部計算用到的數(shù)組使用了滾動數(shù)組(LCSArray)實現(xiàn),空間占用為右邊序列長度*2.


            LCS_Calculate
            的最后一個參數(shù)不為EmptyContainer則會計算公共子序列在左右序列中各段的順序和長度.這里L_Iterator是不是隨機訪問迭代器就會影響到性能了.L_Iterator不是隨機迭代器內部就會用到一個動態(tài)增長的輔助數(shù)組(TrackArrayDynamic)來做回溯; L_Iterator是隨機迭代器則直接一次申請(左序列*右序列)這么大的空間(TrackArrayStatic)來輔助回溯計算.
            而如果LCS_Calculate的最后一個參數(shù)為EmptyContainer則會選擇一個空數(shù)組(TrackArrayEmpty)實現(xiàn).TrackArrayEmpty類把所有操作展開為空操作.

            所有這些,基于模板來自動選擇.用戶不需要指定不同的函數(shù)來優(yōu)化性能:

            template<typename L_Iterator,typename R_Iterator,typename Container/*vector<LCS_Section>*/>
            LCS_Size LCS_Calculate(L_Iterator lbeg,L_Iterator lend,
                                R_Iterator rbeg,R_Iterator rend,
                                Container 
            &out)
            {
                
            out.clear();
                detail::LCSArray array(rend
            -rbeg);
               typedef detail::SelectTrackArray
            <Container,typename std::iterator_traits<L_Iterator>::iterator_category> SelectTrack;//選擇適當?shù)幕厮輸?shù)組
               typename SelectTrack::Array trackArr(SelectTrack::TotalRows(lbeg,lend),array.columns());//選擇適當?shù)幕厮輸?shù)組
                LCS_Size leftSize;
                LCS_Size rightSize;
              
            for( leftSize=1;lbeg!=lend;++lbeg,++leftSize)//外層只需要是輸入迭代器就可
                    
            for( rightSize=1;rightSize<=array.columns();++rightSize)
                    
            {
                        
            if(LCS_Compare_Trait::equal(*lbeg,*(rbeg+rightSize-1))){
                            array(leftSize,rightSize)
            =array(leftSize-1,rightSize-1)+1;
                            trackArr(leftSize,rightSize)
            =0;
                        }

                        
            else if(array(leftSize-1,rightSize)>=array(leftSize,rightSize-1)){
                            array(leftSize,rightSize)
            =array(leftSize-1,rightSize);
                            trackArr(leftSize,rightSize)
            =1;
                        }

                        
            else{
                            array(leftSize,rightSize)
            =array(leftSize,rightSize-1);
                            trackArr(leftSize,rightSize)
            =-1;
                        }


                    }

                    detail::LCS_KeepTrack(trackArr,
            out);

                
            return array(leftSize-1,array.columns());

            }


            完整代碼包括測試代碼下載

            posted @ 2010-03-27 19:31 FireEmissary 閱讀(2829) | 評論 (1)編輯 收藏

            僅列出標題
            共2頁: 1 2 
            久久免费美女视频| 国产香蕉久久精品综合网| 97精品国产91久久久久久| 久久久av波多野一区二区| 久久久久久国产精品免费无码| av无码久久久久不卡免费网站| 精品国产91久久久久久久a | 欧美一级久久久久久久大| 伊人情人综合成人久久网小说| 久久婷婷五月综合97色| 国产99久久久国产精品~~牛| 亚洲国产一成人久久精品| 97r久久精品国产99国产精| 午夜精品久久久久久影视777 | 99久久国语露脸精品国产| 久久人妻少妇嫩草AV无码蜜桃| 久久精品国产亚洲AV无码娇色 | 无码人妻少妇久久中文字幕蜜桃| 麻豆精品久久精品色综合| 77777亚洲午夜久久多喷| 99久久国语露脸精品国产| 亚洲AV无码久久精品蜜桃| 久久丝袜精品中文字幕| 久久精品草草草| 一本色道久久88精品综合| 亚洲精品国产综合久久一线| 久久久91精品国产一区二区三区| 99久久99久久精品国产片果冻| 人人狠狠综合久久亚洲高清| 久久777国产线看观看精品| 少妇久久久久久被弄高潮| 久久精品国产亚洲av麻豆蜜芽| 久久亚洲天堂| 亚洲伊人久久综合中文成人网| 精品久久久久中文字| 国产AV影片久久久久久| 国产三级久久久精品麻豆三级| 少妇高潮惨叫久久久久久| 亚洲乱码中文字幕久久孕妇黑人 | 日韩久久无码免费毛片软件| 欧美粉嫩小泬久久久久久久 |