• <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>
              回復  更多評論   

            特殊功能
             
            久久无码AV一区二区三区| 久久久久久综合一区中文字幕| 亚洲精品乱码久久久久久蜜桃图片| 香蕉久久夜色精品国产2020 | 无码精品久久久天天影视| 无码人妻精品一区二区三区久久| 精品国际久久久久999波多野| 久久精品国产99久久丝袜| 亚洲欧洲中文日韩久久AV乱码| 亚洲欧美一区二区三区久久| 亚洲综合伊人久久大杳蕉| 精品国产一区二区三区久久蜜臀| 久久国产劲爆AV内射—百度| …久久精品99久久香蕉国产| 久久国产高潮流白浆免费观看| 国产精品伊人久久伊人电影 | 国产成人久久激情91| 一级做a爰片久久毛片看看| 99久久成人国产精品免费| 久久天天躁狠狠躁夜夜2020 | 国内精品久久久久久久亚洲| 色综合久久久久综合体桃花网| 久久99亚洲综合精品首页| 国产午夜精品久久久久免费视| 国产欧美久久久精品影院| 精品水蜜桃久久久久久久| 精品一区二区久久| 久久国产精品-国产精品| 久久无码国产专区精品| 四虎久久影院| 久久精品国产亚洲AV不卡| 久久久久亚洲AV无码专区网站| 青青青国产精品国产精品久久久久| 久久亚洲AV成人无码| 亚洲精品WWW久久久久久| 久久无码精品一区二区三区| 国产香蕉97碰碰久久人人| 一本色道久久88加勒比—综合| 久久久久一级精品亚洲国产成人综合AV区| 777米奇久久最新地址| 久久99精品国产自在现线小黄鸭|