• <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記錄開發(fā)新知道

            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 閱讀(773) 評論(2)  編輯 收藏 引用 所屬分類: C/C++

            評論

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

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

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

            template <class T>
              回復(fù)  更多評論   

            特殊功能
             
            久久精品亚洲乱码伦伦中文| 亚洲∧v久久久无码精品| 国产免费久久精品99久久| 88久久精品无码一区二区毛片 | 久久99国产精品久久久| 久久综合综合久久狠狠狠97色88| 日韩美女18网站久久精品| 青青草国产精品久久| 久久乐国产精品亚洲综合| 久久综合狠狠综合久久综合88| 久久婷婷久久一区二区三区| 久久久久女教师免费一区| 亚洲精品无码久久久影院相关影片| 国产精品一区二区久久精品无码| 成人午夜精品无码区久久 | 精品久久久无码中文字幕| 亚洲精品乱码久久久久66| 久久久国产精品| 亚洲伊人久久大香线蕉苏妲己| 久久频这里精品99香蕉久| 91精品国产91久久| 香蕉久久av一区二区三区| 日韩va亚洲va欧美va久久| 青青草国产精品久久| 精品综合久久久久久97超人 | 亚洲精品无码久久千人斩| 久久久久国产视频电影| 97超级碰碰碰碰久久久久| 久久久久人妻一区二区三区| 开心久久婷婷综合中文字幕| 亚洲一本综合久久| 99久久综合狠狠综合久久| 97久久香蕉国产线看观看| 久久综合九色综合精品| 久久天天躁狠狠躁夜夜网站| 亚洲色大成网站www久久九| 久久99精品久久久大学生| 久久精品aⅴ无码中文字字幕不卡| 精品久久久久成人码免费动漫| 亚洲一级Av无码毛片久久精品| 欧洲性大片xxxxx久久久|