• <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 閱讀(759) 評論(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>
              回復  更多評論   

            特殊功能
             
            久久婷婷色香五月综合激情| 久久综合九色综合97_久久久| 99国产精品久久| 欧美喷潮久久久XXXXx| 热re99久久精品国产99热| 国内精品久久久久久野外| 久久久精品国产亚洲成人满18免费网站 | 久久婷婷五月综合国产尤物app| 久久99精品国产自在现线小黄鸭| 久久免费小视频| 久久久www免费人成精品| 欧美激情精品久久久久| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 伊人热热久久原色播放www| 漂亮人妻被黑人久久精品| 日本精品久久久中文字幕| 久久精品国产亚洲AV不卡| 国产一区二区三精品久久久无广告 | 久久国产精品一国产精品金尊| 很黄很污的网站久久mimi色| 无码人妻精品一区二区三区久久| 久久精品国产亚洲av瑜伽| 国产成人无码久久久精品一| 亚洲欧洲久久av| 麻豆久久| 久久久久国色AV免费观看| 97超级碰碰碰碰久久久久| 久久ZYZ资源站无码中文动漫| 久久久久久国产精品无码下载 | 久久人人爽人人爽人人片AV高清| 99久久免费只有精品国产| 国产亚洲欧美成人久久片| 久久婷婷五月综合97色| 午夜精品久久久久久久久| 无码人妻少妇久久中文字幕| 久久国产免费直播| 久久久久成人精品无码| 久久久精品久久久久特色影视| 久久久久国产一区二区三区| 久久久99精品一区二区| 人妻丰满?V无码久久不卡|