• <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ù)  更多評論   

            特殊功能
             
            欧美午夜A∨大片久久 | 99久久国产综合精品女同图片| 久久99精品久久久久久野外| 狠狠久久综合| 蜜臀av性久久久久蜜臀aⅴ| 成人精品一区二区久久| 午夜精品久久久久成人| 99久久无色码中文字幕| 午夜精品久久久久成人| 久久精品成人免费网站| 亚洲国产精品无码久久九九| 久久久久亚洲AV无码永不| 久久精品国产一区二区电影| 亚洲AV无一区二区三区久久| 国产99久久久国产精免费| 婷婷综合久久中文字幕蜜桃三电影| 久久精品国产精品青草app| 97精品伊人久久大香线蕉| 色综合久久中文色婷婷| 无码人妻精品一区二区三区久久久 | 无码人妻少妇久久中文字幕蜜桃| 国产精品永久久久久久久久久 | 色婷婷综合久久久久中文| 精品久久综合1区2区3区激情 | 久久久久黑人强伦姧人妻| 国产99精品久久| 国产精品久久午夜夜伦鲁鲁| 国产美女亚洲精品久久久综合| 久久久久免费视频| 久久国产香蕉一区精品| 国产成人无码精品久久久免费| 国产精品久久久亚洲| 91久久婷婷国产综合精品青草| 久久久无码精品亚洲日韩京东传媒| 久久久精品国产Sm最大网站| 夜夜亚洲天天久久| 久久午夜电影网| 久久精品国产亚洲一区二区三区 | 久久精品国产亚洲av瑜伽| 狠狠精品久久久无码中文字幕| 中文精品久久久久国产网址|