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

            CG@CPPBLOG

            /*=========================================*/
            隨筆 - 76, 文章 - 39, 評論 - 137, 引用 - 0
            數(shù)據(jù)加載中……

            《C++設(shè)計新思維》讀書筆記(15)

            2.10.2 偵測基本型別(略)'
            2.10.3
            優(yōu)化的參數(shù)型別(略)
            2.10.4 卸除飾詞

            下面是一個“const 卸除器

             1 template<typename T>
             2 class TypeTraits
             3 {
             4 private:
             5     template<class U> struct UnConst
             6     {
             7         typedef U Result;
             8     };
             9     template<class U> struct UnConst<const U>
            10     {
            11         typedef U Result;
            12     };
            13 public:
            14     typedef UnConst<T>::Result NonConstType;
            15 };

            2.10.5 運用TypeTraits

            這里實作一個調(diào)用BitBlast的例子: 

             1 enum CopyAlgoSelector{Conservative, Fast};
             2 
             3 // Conservative routine-works for any type
             4 template <typename InIt, typename OutIt>
             5 OutIt CopyImpl(InIt first, InIt last, OutIt result, Int2Type<Conservative>)
             6 {
             7     for(; first != last; ++first, ++result)
             8         *result = *first;
             9 }
            10 
            11 // Fast routine-works only for pointers to raw data
            12 template <typename InIt, typename OutIt>
            13 OutIt CopyImpl(InIt first, InIt last, OutIt result, Int2Type<Fast>)
            14 {
            15     const size_t n = last - first;
            16     BitBlast(first, result, n * sizeof(*first));
            17     return result + n;
            18 }
            19 
            20 template<typename T> struct SupportsBitwiseCopy
            21 {
            22     enum{result = TypeTraits<T>::isStdFundamental};
            23 }
            24 
            25 template <typename InIt, typename OutIt>
            26 OutIt Copy(InIt first, InIt last, OutIt result)
            27 {
            28     typedef TypeTraits<InIt>::PointeeType SrcPointee;
            29     typedef TypeTraits<OutIt>::PointeeType DestPointee;
            30     enum { copyAlgo =
            31         TypeTraits<InIt>::IsPointer &&
            32         TypeTraits<OutIt>::IsPointer &&
            33         SupportsBitwiseCopy<SrcPointee>::result &&
            34         SupportsBitwiseCopy<DestPointee>::result &&
            35         sizeof(SrcPointee) == sizeof(DestPointee) };
            36     return CopyImpl(first, last, Int2Type<useBitBlast>);
            37 }

            對于一個POD結(jié)構(gòu)(plain old data),即C struct,只有數(shù)據(jù)沒有其它任何東西。因為無法甄別其類型,會調(diào)用慢速版本。我們可以這樣做,讓它調(diào)用快速版本,假如POD結(jié)構(gòu)為Mytype

            1 template<> struct SupportsBitwiseCopy<MyTyee>
            2 {
            3     enum {result = true};
            4 };

            posted on 2007-12-25 21:43 cuigang 閱讀(325) 評論(0)  編輯 收藏 引用 所屬分類: 《C++設(shè)計新思維》讀書筆記

            一级做a爰片久久毛片16| 青青青青久久精品国产h久久精品五福影院1421 | 伊人久久大香线蕉影院95| 久久综合丝袜日本网| 亚洲七七久久精品中文国产 | 狠狠精品久久久无码中文字幕 | 国产午夜精品久久久久九九电影| 欧洲国产伦久久久久久久| 久久99亚洲网美利坚合众国| 久久国产色av免费看| 精品久久久久久中文字幕| 久久久久国产精品三级网| 久久精品人人槡人妻人人玩AV| 国产日韩久久免费影院| 午夜精品久久久久久中宇| 久久国产精品国语对白| 色狠狠久久AV五月综合| 亚洲国产精品综合久久网络| 91精品国产色综久久| 亚洲AV日韩AV永久无码久久| 女同久久| 99久久国产主播综合精品| 久久人妻少妇嫩草AV无码专区| 性欧美大战久久久久久久| 久久久青草青青亚洲国产免观| 浪潮AV色综合久久天堂| 久久青青草视频| 日本精品久久久久久久久免费| 91麻精品国产91久久久久| 国产成人精品白浆久久69| 中文字幕乱码久久午夜| 中文成人无码精品久久久不卡 | 少妇内射兰兰久久| 伊人久久大香线蕉av一区| 亚洲精品视频久久久| 久久青青草原亚洲av无码| 99久久国产亚洲高清观看2024| 爱做久久久久久| 国产2021久久精品| 国产精品成人无码久久久久久 | 久久亚洲AV成人无码国产|