• <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
            數據加載中……

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

            2.10.2 偵測基本型別(略)'
            2.10.3
            優化的參數型別(略)
            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

            這里實作一個調用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結構(plain old data),即C struct,只有數據沒有其它任何東西。因為無法甄別其類型,會調用慢速版本。我們可以這樣做,讓它調用快速版本,假如POD結構為Mytype。

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

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

            久久久久99精品成人片直播| 久久久久综合网久久| 久久久亚洲AV波多野结衣| 久久久久亚洲av无码专区| 国产免费久久精品丫丫| 无码任你躁久久久久久老妇| 欧美牲交A欧牲交aⅴ久久| 国产精品综合久久第一页| 亚洲中文字幕久久精品无码喷水 | 久久精品a亚洲国产v高清不卡| 精品久久一区二区三区| A级毛片无码久久精品免费| 伊人久久综在合线亚洲2019 | 伊人久久大香线蕉亚洲| 九九热久久免费视频| 久久超碰97人人做人人爱| 综合久久一区二区三区 | 精品国产VA久久久久久久冰 | 欧美精品一区二区精品久久| 久久久久久精品成人免费图片| 香蕉久久夜色精品国产小说| 日日躁夜夜躁狠狠久久AV| 国产精品久久久久久久久久影院| 久久免费美女视频| 国产亚洲婷婷香蕉久久精品| 无遮挡粉嫩小泬久久久久久久 | 久久综合狠狠综合久久| 久久无码国产专区精品| 亚洲精品无码专区久久同性男| 久久99热这里只有精品国产| 99久久成人18免费网站| 国产亚洲美女精品久久久久狼| 亚洲精品无码久久久久去q | 国产Av激情久久无码天堂| 久久精品中文字幕无码绿巨人| 色8久久人人97超碰香蕉987| 久久亚洲日韩精品一区二区三区| 无码伊人66久久大杳蕉网站谷歌 | 伊人久久大香线蕉av不变影院| 久久99热这里只有精品66| 久久久久久久久波多野高潮|