• <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++設計新思維》讀書筆記

            久久婷婷五月综合97色一本一本| 久久人妻AV中文字幕| 亚洲国产另类久久久精品小说| 国产成人精品综合久久久久| 亚洲成色999久久网站| 亚洲国产精品嫩草影院久久| 午夜久久久久久禁播电影| 久久精品国产精品青草app| 区久久AAA片69亚洲| 国产激情久久久久影院| AV色综合久久天堂AV色综合在 | 亚洲精品综合久久| 久久婷婷五月综合97色一本一本 | 亚洲AV日韩AV天堂久久| 久久电影网| 国产精品永久久久久久久久久 | 亚洲精品高清久久| 97精品伊人久久久大香线蕉| 国产一区二区精品久久凹凸| 国产成人久久激情91| 国产精品美女久久久久| 久久精品极品盛宴观看| 久久国产免费| 精品久久人人做人人爽综合| 久久超碰97人人做人人爱| 久久66热人妻偷产精品9| 婷婷久久精品国产| 久久99这里只有精品国产| 国产精品成人99久久久久| 久久精品国产只有精品2020| 久久亚洲精品成人AV| 久久婷婷五月综合97色一本一本 | 精品久久久久久久久久中文字幕 | 99久久精品免费看国产一区二区三区| 嫩草影院久久国产精品| 久久996热精品xxxx| segui久久国产精品| 亚洲狠狠综合久久| 欧美大战日韩91综合一区婷婷久久青草 | 国产精品永久久久久久久久久| 久久久久久免费一区二区三区|