• <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記錄開發(fā)新知道

            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 閱讀(773) 評論(2)  編輯 收藏 引用 所屬分類: C/C++

            評論

            # re: C++ Traits 2010-06-03 15:57 brainpoint

            特化代碼寫得不夠美啊  回復(fù)  更多評論   

            # re: C++ Traits 2010-08-29 17:30 evening dresses

            template <class T>
              回復(fù)  更多評論   

            特殊功能
             
            日本加勒比久久精品| 久久精品免费一区二区| 亚洲AV成人无码久久精品老人| 久久人妻无码中文字幕| 无码国内精品久久人妻蜜桃 | 久久精品国产亚洲Aⅴ蜜臀色欲| 色婷婷狠狠久久综合五月| 麻豆一区二区99久久久久| 热re99久久精品国产99热| 久久综合九色综合久99| 99久久er这里只有精品18| 欧美精品一区二区久久| 国产亚洲色婷婷久久99精品| 女同久久| 久久99精品国产| 久久综合给合久久狠狠狠97色69| 久久精品国产亚洲一区二区三区| 亚洲AV成人无码久久精品老人| 久久精品无码一区二区app| 97精品久久天干天天天按摩| 91麻豆国产精品91久久久| 97精品伊人久久久大香线蕉| 久久综合国产乱子伦精品免费| 亚洲午夜久久久| 久久亚洲电影| 国产福利电影一区二区三区久久老子无码午夜伦不 | 99久久精品国产一区二区| 久久久久97国产精华液好用吗| 久久免费的精品国产V∧| 久久国产免费直播| 一本久久免费视频| 亚洲国产精品无码久久九九 | 亚洲综合久久夜AV | 久久久艹| 日本加勒比久久精品| 亚洲国产精品一区二区三区久久 | 久久久久女人精品毛片| 一个色综合久久| 婷婷久久综合九色综合绿巨人| 麻豆久久| 国产亚洲美女精品久久久2020|