• <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>
              回復  更多評論   

            特殊功能
             
            久久久精品波多野结衣| 久久精品人人做人人爽电影蜜月| 九九99精品久久久久久| 国内精品久久久久久久coent| 亚洲精品无码专区久久同性男| 亚洲色欲久久久久综合网| 精品国产乱码久久久久久1区2区| 伊人久久综合热线大杳蕉下载| 2020久久精品亚洲热综合一本| 中文字幕久久欲求不满| 亚洲国产成人久久综合野外| 久久99国产精品久久| 免费精品国产日韩热久久| 69SEX久久精品国产麻豆| 日韩一区二区三区视频久久| 久久伊人精品青青草原高清| 久久久精品国产Sm最大网站| 久久精品免费一区二区三区| 一级女性全黄久久生活片免费 | 亚洲欧美一级久久精品| 国产精品久久久久AV福利动漫| 免费一级做a爰片久久毛片潮| 久久91精品国产91久久小草| 亚洲AV日韩精品久久久久久久| 久久精品综合一区二区三区| 人人狠狠综合久久亚洲婷婷| 亚洲日本va中文字幕久久| 亚洲精品午夜国产va久久| 亚洲国产精品狼友中文久久久 | 无码任你躁久久久久久久| 久久精品视频91| 久久久久亚洲AV成人网人人网站| 精品国产综合区久久久久久| 色综合久久久久网| 久久精品免费一区二区三区| 青青草原综合久久大伊人精品| AV色综合久久天堂AV色综合在| 久久ww精品w免费人成| 日产精品久久久久久久性色| 国内精品人妻无码久久久影院| 久久精品国产亚洲综合色|