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

            特殊功能
             
            久久精品国产久精国产思思| 色偷偷88888欧美精品久久久| 香港aa三级久久三级| 99久久精品免费看国产一区二区三区 | 久久精品人妻中文系列| 99久久免费国产精品特黄| 久久热这里只有精品在线观看| 精品久久久噜噜噜久久久| 品成人欧美大片久久国产欧美...| 久久久久国产精品三级网| 日产精品久久久久久久| 66精品综合久久久久久久| 久久免费看黄a级毛片| 天天久久狠狠色综合| 亚洲人成网亚洲欧洲无码久久| 久久精品国产亚洲一区二区| 99久久免费国产精品特黄| 国产成人无码精品久久久免费| 少妇人妻88久久中文字幕| 久久综合狠狠综合久久97色| 国内精品久久久久影院优| 热99RE久久精品这里都是精品免费| 国产精品99久久久久久人| 国内精品久久久久影院薰衣草| 99久久精品国产一区二区| 久久夜色精品国产噜噜亚洲AV| 日韩亚洲国产综合久久久| 国产激情久久久久影院| 久久亚洲精品视频| 久久亚洲欧美日本精品| 91久久精品91久久性色| 久久人人妻人人爽人人爽| 国内精品久久久久久久久电影网| 久久精品中文字幕大胸| 久久综合九色欧美综合狠狠| 久久成人永久免费播放| 久久精品二区| 亚洲一区精品伊人久久伊人| 一级做a爰片久久毛片看看 | 91精品国产高清久久久久久91 | 色99久久久久高潮综合影院|