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

            woaidongmao

            文章均收錄自他人博客,但不喜標(biāo)題前加-[轉(zhuǎn)貼],因其丑陋,見諒!~
            隨筆 - 1469, 文章 - 0, 評(píng)論 - 661, 引用 - 0
            數(shù)據(jù)加載中……

            STL中迭代器traits技巧學(xué)習(xí) : 一個(gè)簡(jiǎn)單的測(cè)試程序

            // testTraits_02.cpp : Defines the entry point for the console application.

            //

             

            //Author : cppgp

            //Email  : cppgp@163.com

            //Time   : 2007 03 08

             

            //功能 : 測(cè)試 C++ template traits 技巧

            //版權(quán) : 可任意轉(zhuǎn)載、拷貝、修改、使用,但請(qǐng)注明原作者姓名

             

            //vc 6.0 下必須去掉 label_traits 的特化版本才能通過編譯鏈接

            //gcc  下面 label_traits 特化版本測(cè)試通過

            #include "StdAfx.h"

            #include <iostream>

             

            using namespace std;

             

            //下面定義五種測(cè)試標(biāo)簽

             

            struct label_1{};

            struct label_2{};

            struct label_3 : public label_2{};

            struct label_4 : public label_3{};

            struct label_5 : public label_4{};

             

            //下面定義五種標(biāo)簽對(duì)應(yīng)的模板類型

             

            //另注 : _Tp 對(duì)應(yīng)的 value_type 沒有用到

            //只是做為一種型別存在而已

            //當(dāng)然你可以不要它!

            template<class _Tp>

            struct lable_1_type

            {

                typedef label_1 label_type;

                typedef _Tp value_type;

            };

             

            template<class _Tp>

            struct lable_2_type

            {

                typedef label_2 label_type;

                typedef _Tp value_type;

            };

             

            template<class _Tp>

            struct lable_3_type

            {

                typedef label_3 label_type;

                typedef _Tp value_type;

            };

             

            template<class _Tp>

            struct lable_4_type

            {

                typedef label_4 label_type;

                typedef _Tp value_type;

            };

             

            template<class _Tp>

            struct lable_5_type

            {

                typedef label_5 label_type;

                typedef _Tp value_type;

            };

             

            //下面是特性萃取 : 分別是泛化和特化版本

             

            template <class label>

            struct label_traits

            {

                typedef typename label::label_type label_type;

                typedef typename label::value_type value_type;

            };

             

            #if 0 //如果是 gcc , 0 修改為 1 即可

             

            template <class label>

            struct label_traits<label*>

            {

                typedef label_5 label_type;

                typedef label value_type;

            };

             

            template <class label>

            struct label_traits<const label*>

            {

                typedef label_5 label_type;

                typedef label value_type;

            };

             

            #endif

             

            //下面是生成標(biāo)簽類型的臨時(shí)變量,其本質(zhì)如同 int() 生成 int 臨時(shí)變量一樣

             

            template <class label>

            inline typename label_traits<label>::label_type

            label_type(const label&)

            {

                typedef typename label_traits<label>::label_type Label_Type;

                return Label_Type();

            }

             

            //下面這個(gè)是針對(duì)不同標(biāo)簽寫的對(duì)應(yīng)重載函數(shù)

             

            template<class label>

            inline void _TestFunc(label,label_1)

            {

                cout<<"here label_1"<<endl;

            }

             

            template<class label>

            inline void _TestFunc(label,label_2)

            {

                cout<<"here label_2"<<endl;

            }

             

            template<class label>

            inline void _TestFunc(label,label_3)

            {

                cout<<"here label_3"<<endl;

            }

             

            template<class label>

            inline void _TestFunc(label,label_4)

            {

                cout<<"here label_4"<<endl;

            }

             

            template<class label>

            inline void _TestFunc(label,label_5)

            {

                cout<<"here label_5"<<endl;

            }

             

            //下面這個(gè)是上面函數(shù)的上層封裝調(diào)用

             

            template<class label>

            inline void TestFunc(label& l)

            {

                _TestFunc(l,label_type(l));

            }

             

            //下面是測(cè)試主程序

             

            class TestClass

            {

            };

             

            int main()

            {

                //定義標(biāo)簽對(duì)象

               

                cout<<"\r\n\r\nbegin test ...\r\n\r\n";

               

                //原生

                {

                   cout<<"int :\n";

                   lable_1_type<int> l1;

                   lable_2_type<int> l2;

                   lable_3_type<int> l3;

                   lable_4_type<int> l4;

                   lable_5_type<int> l5;

                   TestFunc(l1);

                   TestFunc(l2);

                   TestFunc(l3);

                   TestFunc(l4);

                   TestFunc(l5);

                   cout<<"\r\n\r\n";

                }

               

                //自定義類型

                {

                   cout<<"test class:\n";

                   lable_1_type<TestClass> l1;

                   lable_2_type<TestClass> l2;

                   lable_3_type<TestClass> l3;

                   lable_4_type<TestClass> l4;

                   lable_5_type<TestClass> l5;

                   TestFunc(l1);

                   TestFunc(l2);

                   TestFunc(l3);

                   TestFunc(l4);

                   TestFunc(l5);

                }

               

                cout<<"\r\ntest end...\r\n\r\n"<<endl;

               

                return 0;

            }

            //結(jié)束

            posted on 2008-11-09 01:35 肥仔 閱讀(719) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C++ 模板

            97久久超碰国产精品2021| 久久人人爽人人爽人人片AV麻豆 | 久久久久国产精品人妻| 久久精品国产免费观看| 久久精品欧美日韩精品| 久久无码AV中文出轨人妻| 国产成人久久精品一区二区三区 | 国产精品久久久久久久久免费| 亚洲成人精品久久| 久久久久久精品免费免费自慰| 国产精品久久久久天天影视| 亚洲国产日韩综合久久精品| 97久久精品无码一区二区天美| 久久青青国产| 狠狠色丁香婷婷综合久久来| 精品久久久久成人码免费动漫 | 97精品国产97久久久久久免费 | 日韩av无码久久精品免费| 大香网伊人久久综合网2020| 蜜臀av性久久久久蜜臀aⅴ| 青青久久精品国产免费看| 国产精品一区二区久久| 午夜天堂av天堂久久久| 九九精品久久久久久噜噜| 国产精品女同一区二区久久| 国产精品美女久久久久网| 久久综合给久久狠狠97色| 久久伊人五月丁香狠狠色| 色综合久久久久综合99| 国产午夜精品久久久久九九| 久久伊人精品青青草原高清| 国产精品久久久久jk制服| 97久久超碰国产精品旧版| 久久91精品国产91久久户| 99久久久精品| 91精品国产色综久久| segui久久国产精品| 国产农村妇女毛片精品久久| 久久久精品日本一区二区三区| 国产精品一区二区久久精品无码 | 国产无套内射久久久国产|