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

            特殊功能
             
            久久久91人妻无码精品蜜桃HD| 久久久久久精品久久久久| 久久久久亚洲AV无码去区首| 2020最新久久久视精品爱| 国产精品久久国产精麻豆99网站| 一本一道久久综合狠狠老| 亚洲级αV无码毛片久久精品| 伊人久久大香线焦AV综合影院| 2021国内精品久久久久久影院| 伊人久久大香线蕉av不变影院| 性做久久久久久久| 伊人久久大香线蕉精品| 国产亚洲欧美精品久久久| 秋霞久久国产精品电影院| 国产成人精品久久| 影音先锋女人AV鲁色资源网久久| 亚洲国产小视频精品久久久三级| 久久精品无码一区二区app| 亚洲va中文字幕无码久久| 91精品国产色综合久久| 亚洲国产香蕉人人爽成AV片久久 | 亚洲国产精品无码久久一线| 97r久久精品国产99国产精| 久久AⅤ人妻少妇嫩草影院| 久久人爽人人爽人人片AV| 久久综合视频网站| 66精品综合久久久久久久| 久久精品毛片免费观看| 欧美性大战久久久久久| 久久婷婷久久一区二区三区| 久久久噜噜噜久久熟女AA片| 国产精品99久久久久久宅男小说| 久久综合久久鬼色| 日本精品久久久久中文字幕| 亚洲级αV无码毛片久久精品| 97精品伊人久久久大香线蕉| 麻豆av久久av盛宴av| 亚洲国产精品无码成人片久久| 亚洲午夜无码久久久久小说| 国产精品美女久久久久AV福利| 久久久久久免费一区二区三区 |