• <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>

            MyMSDN

            MyMSDN記錄開發新知道

            C++ Traits

            本來想好好寫寫C++ Traits的,剛剛接到interview的通知,先貼代碼,改天再議。

            /*
             * cpp_traits.cpp
             *
             *  Created on: 2010-4-26
             *      Author: volnet@tom.com
             */
            #include <iostream>
            // kinds of types for overloading.
            struct undefined_type {};
            struct int32_type {};
            struct int64_type {};
            
            // typedef some has_trivial_* for difference types.
            template <class T>
            struct type_traits {
                typedef undefined_type has_trivial_type;
            };
            
            // define the partial specialization functions.
            template <>
            struct type_traits<int> {
                typedef int32_type has_trivial_type;
            };
            template <>
            struct type_traits<long> {
                typedef int64_type has_trivial_type;
            };
            
            // the dispatcher method for all kinds of types.
            template <class T>
            void type_detect(T& p){
                typedef typename type_traits<T>::has_trivial_type trivial_type;
                type_detect(p, trivial_type());
            }
            
            // define the functions for dispatching.
            template <class T>
            void type_detect(T& p, undefined_type) {
                std::cout << p;
                std::cout << " // It's a undefined type, we have NOT found the dispatcher function." << std::endl;
            }
            template <class T>
            void type_detect(T& p, int32_type) {
                std::cout << p;
                std::cout << " // It's a int32" << std::endl;
            }
            template <class T>
            void type_detect(T& p, int64_type) {
                std::cout << p;
                std::cout << " // It's a int64" << std::endl;
            }
            
            int main(void) {
                int int32num = 2010;
                type_detect(int32num);
            
                long int64num = 2010L;
                type_detect(int64num);
            
                std::string str = "2010";
                type_detect(str);
            
                std::cout << "-------end of program." << std::endl;
                return EXIT_SUCCESS;
            }
            

            posted on 2010-04-26 15:31 volnet 閱讀(775) 評論(2)  編輯 收藏 引用 所屬分類: C/C++

            評論

            # re: C++ Traits 2010-06-03 15:57 brainpoint

            特化代碼寫得不夠美啊  回復  更多評論   

            # re: C++ Traits 2010-08-29 17:30 evening dresses

            template <class T>
              回復  更多評論   

            特殊功能
             
            久久综合亚洲鲁鲁五月天| 久久午夜无码鲁丝片秋霞| 精品久久8x国产免费观看| 久久99国产精品久久99| 一本大道久久a久久精品综合| 婷婷综合久久狠狠色99h| 国产午夜精品久久久久九九电影| 久久免费香蕉视频| 国产亚洲精久久久久久无码77777| 久久精品九九亚洲精品| 久久www免费人成看国产片| 精品久久久久成人码免费动漫 | 国产精品免费久久久久电影网| 国产精品青草久久久久福利99| 国产成人久久精品一区二区三区| 99久久精品费精品国产一区二区| 无码乱码观看精品久久| 久久亚洲国产午夜精品理论片| 亚洲午夜久久久影院伊人| 久久精品亚洲精品国产欧美| 国内精品人妻无码久久久影院| 久久99精品久久久久久秒播| 久久大香香蕉国产| 人妻精品久久久久中文字幕69| 久久综合亚洲色HEZYO国产| 国产精品久久永久免费| 久久国产高潮流白浆免费观看| 久久精品卫校国产小美女| 香港aa三级久久三级老师2021国产三级精品三级在 | 少妇人妻88久久中文字幕| 中文字幕精品无码久久久久久3D日动漫 | 99精品国产综合久久久久五月天 | 亚洲国产精品高清久久久| 亚洲国产精品综合久久一线| 一级做a爱片久久毛片| 精品久久一区二区三区| 国产美女久久久| 99热成人精品免费久久| 久久精品无码一区二区app| 女同久久| 亚洲狠狠婷婷综合久久久久|