• <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精品国产一区二区三区| 久久99热这里只有精品国产| 色99久久久久高潮综合影院| 国产精品一久久香蕉国产线看观看| 一本色道久久88综合日韩精品| 色综合久久久久无码专区 | 国内精品免费久久影院| 久久无码高潮喷水| 四虎影视久久久免费| 青青草原精品99久久精品66| 国产精品久久新婚兰兰| 久久免费小视频| 91精品国产色综合久久| 精品久久久久久无码专区| 天堂无码久久综合东京热| 久久国产高清字幕中文| 久久天天躁狠狠躁夜夜不卡| 久久久www免费人成精品| 亚洲国产二区三区久久| 91精品国产综合久久香蕉| 久久久久亚洲av无码专区导航 | 亚洲国产精品无码久久九九 | 亚洲AV日韩AV永久无码久久| 婷婷久久综合九色综合绿巨人| 国产精品嫩草影院久久| 国内精品久久久久久久久电影网| 久久婷婷激情综合色综合俺也去| 狠狠色丁香久久婷婷综合图片 | 国内精品久久久久影院亚洲| 中文字幕精品无码久久久久久3D日动漫 | 久久久久亚洲AV无码观看| 久久久亚洲裙底偷窥综合| 日日狠狠久久偷偷色综合0|