• <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久久er这里只有精品18| 蜜臀久久99精品久久久久久| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久Av无码精品人妻系列 | 久久丫精品国产亚洲av不卡| 色成年激情久久综合| 三级片免费观看久久| 国产精品99久久精品| 久久亚洲国产成人影院| 99久久精品九九亚洲精品| 久久久久无码精品国产不卡| 一级做a爰片久久毛片毛片| 欧美伊香蕉久久综合类网站| 99精品国产99久久久久久97| 久久久久人妻一区精品果冻| 97久久超碰国产精品2021| 亚洲精品蜜桃久久久久久| 免费一级欧美大片久久网| 色综合久久综合网观看| 99久久中文字幕| 国产精品久久久久久吹潮| 亚洲国产精品久久久天堂| 久久亚洲sm情趣捆绑调教| 欧美日韩精品久久久久| 久久e热在这里只有国产中文精品99 | 9999国产精品欧美久久久久久| 久久丫精品国产亚洲av| 国内精品久久久久久久久电影网| 香港aa三级久久三级老师2021国产三级精品三级在| 国产精品久久久久…| 国产精品久久久久影视不卡 | 色综合久久88色综合天天| 国内精品久久久久久99蜜桃| 久久亚洲私人国产精品vA| 久久香蕉超碰97国产精品| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 999久久久免费精品国产| 国内精品久久久久伊人av | 超级碰碰碰碰97久久久久| 久久亚洲熟女cc98cm|