• <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>

            visualfc

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              42 隨筆 :: 0 文章 :: 119 評論 :: 0 Trackbacks
            原創(chuàng) visualfc

            介紹一個通用c++ typeid實現(xiàn).

            主要功能:
               通用的typeid實現(xiàn),可以在VS60/VS2005以及mingw32下保證相同的類型名輸出.
               程序使用boost::type_traits來實現(xiàn),沒有使用內(nèi)置的typeid.不支持RTTI操作.
             
            局限:
               目前版本v0.2僅實現(xiàn)一層function_ptr和member_function_ptr解析操作.

            版本歷史:
               v0.2 不再使用std::string.去除了std_name成員函數(shù)
               將 vfc::type_id_t<T>::name() 更改為 vfc::type_id_t<T>().name()

            項目地址:
                http://code.google.com/p/typeid

            主要類介紹:
               template<typename T>  vfc::type_id_t<>  獲取類型的typeid名
               template<typename T>  vfc::type_id(const T & t) 獲取變量的類型的type_id_t類型.

            主要函數(shù):
               type_id_t<int>().name() 輸出 const char * 類型的typename
               type_id(100).name()     輸出 const char * 類型的typename

            定義類型:
               VFC_TYPE_ID(type,id) 實現(xiàn)類型的定義,type為類型,id為類型自定義數(shù)值標(biāo)識
            例: VFC_TYPE_ID(std::string,0x2001)

            下面給出一個完整的例子:
             1 #include <stdio.h>
             2 #include "vfc_type.h"
             3 
             4 struct a
             5 {
             6     const int * test(int,int)
             7     {
             8         return NULL;
             9     }
            10 
            11     void test1() const
            12     {
            13     }
            14     const char * test2(intintvolatile
            15     {
            16         return NULL;
            17     }
            18     const int & test3(int *const char *const volatile
            19     {
            20         static int i = 100;
            21         return i;
            22     }
            23 };
            24 
            25 void test(const char *int k)
            26 {
            27 };
            28 
            29 VFC_TYPE_ID(a,0x2000);
            30 
            31 
            32 int main(int argc, char* argv[])
            33 {
            34     typedef void (*T1)(void);
            35     typedef int (*T2)(void);
            36     typedef int (*T3)(int,int,int,int,int,int,int,int,int);
            37     typedef const char * (*T4)(int &,int *,char **,char &,const int &);
            38 
            39     typedef int U1;
            40     typedef int U2[5];
            41     typedef const int & U3;
            42     typedef char U4[5][6][7];
            43 
            44     printf("T1 type %s\n",vfc::type_id_t<T1>().name());
            45     printf("T2 type %s\n",vfc::type_id_t<T2>().name());
            46     printf("T3 type %s\n",vfc::type_id_t<T3>().name());
            47     printf("T4 type %s\n",vfc::type_id_t<T4>().name());
            48 
            49     printf("U1 type %s\n",vfc::type_id_t<U1>().name());
            50     printf("U2 type %s\n",vfc::type_id_t<U2>().name());
            51     printf("U3 type %s\n",vfc::type_id_t<U3>().name());
            52     printf("U4 type %s\n",vfc::type_id_t<U4>().name());
            53 
            54     printf("\'d\' type %s\n",vfc::type_id('d').name());
            55     printf("100 type %s\n",vfc::type_id(100).name());
            56     printf("100.0 type %s\n",vfc::type_id(100.0).name());
            57     printf("\"str\" type %s\n",vfc::type_id("str").name());
            58 
            59     const char * str = "ok";
            60     printf("const char * str type %s\n",vfc::type_id(str).name());
            61 
            62     a * pa;
            63     printf("a type %s\n",vfc::type_id_t<a>().name());
            64     printf("pa type %s\n",vfc::type_id(pa).name());
            65     printf("a::test type %s\n",vfc::type_id(&a::test).name());
            66     printf("a::test type %s\n",vfc::type_id(&a::test1).name());
            67     printf("a::test type %s\n",vfc::type_id(&a::test2).name());
            68     printf("a::test type %s\n",vfc::type_id(&a::test3).name());
            69     printf("test %s\n",vfc::type_id(&test).name());
            70     
            71     typedef int (a::*TT)(const int *,charconst volatile;
            72     const TT * tt;
            73     printf("TT type %s\n",vfc::type_id_t<TT>().name());
            74     printf("const TT * type %s\n",vfc::type_id(tt).name());
            75 
            76     return 0;
            77 }
            78
            在VC60/ VC2003/VC2005/MinGW32下輸出相同運行結(jié)果
            T1 type void (*)()
            T2 type 
            int (*)()
            T3 type 
            int (*)(int,int,int,int,int,int,int,int,int)
            T4 type 
            char const * (*)(int &,int *,char * *,char &,int const &)
            U1 type 
            int
            U2 type 
            int [5]
            U3 type 
            int const &
            U4 type 
            char [7] [6] [5]
            'd' type char
            100 type int
            100.0 type double
            "str" type char [4]
            const char * str type char const *
            a type a
            pa type a 
            *
            a::test type 
            int const * (a::*)(int,int)
            a::test type 
            void (a::*)()const
            a::test type 
            char const * (a::*)(int,int)volatile
            a::test type 
            int const & (a::*)(int *,char const *)const volatile
            test 
            void (*)(char const *,int)
            TT type 
            int (a::*)(int const *,char)const volatile
            const TT * type int (a::*const *)(int const *,char)const volatile


            posted on 2008-11-04 22:30 visualfc 閱讀(1602) 評論(0)  編輯 收藏 引用 所屬分類: C++
            成人综合久久精品色婷婷| 99久久精品国产麻豆| 91精品国产91热久久久久福利| 无码国产69精品久久久久网站| 久久综合久久鬼色| 久久无码人妻精品一区二区三区| 国产成人无码精品久久久免费 | 久久婷婷是五月综合色狠狠| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 国产精品久久久久一区二区三区| 7国产欧美日韩综合天堂中文久久久久| 91精品国产色综合久久| 久久久中文字幕| 国内精品久久久久久麻豆| 久久综合九色欧美综合狠狠| 久久亚洲sm情趣捆绑调教| 久久久噜噜噜久久中文福利| 久久精品国产精品国产精品污| 99久久婷婷国产一区二区| 欧美久久一级内射wwwwww.| 人人妻久久人人澡人人爽人人精品| 久久精品久久久久观看99水蜜桃| 久久综合久久自在自线精品自| 亚洲国产精品热久久| 人妻少妇精品久久| 蜜臀av性久久久久蜜臀aⅴ| 99久久成人18免费网站| 人妻无码αv中文字幕久久琪琪布| 久久永久免费人妻精品下载| 品成人欧美大片久久国产欧美...| 亚洲国产成人精品91久久久| 99国产欧美久久久精品蜜芽| 精品欧美一区二区三区久久久| 天堂久久天堂AV色综合| 国产亚州精品女人久久久久久 | 国产精品久久久香蕉| 韩国无遮挡三级久久| 国产精品久久久久久久久软件| 少妇高潮惨叫久久久久久| 久久一区二区三区99| 欧美亚洲国产精品久久蜜芽|