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

            2022年国产精品久久久久| 三级片免费观看久久| 久久久这里只有精品加勒比| 亚洲天堂久久久| 少妇高潮惨叫久久久久久| 97久久精品人人澡人人爽| 狠狠色丁香久久婷婷综合图片| 波多野结衣中文字幕久久| 国产精品免费久久久久电影网| 色欲久久久天天天综合网| 久久免费视频网站| 色婷婷久久综合中文久久蜜桃av| 久久亚洲国产欧洲精品一| 国产精品久久新婚兰兰| 青草影院天堂男人久久| 亚洲级αV无码毛片久久精品| 久久99精品国产麻豆不卡| 久久精品一区二区三区不卡| 婷婷久久久亚洲欧洲日产国码AV| 伊人丁香狠狠色综合久久| 日本人妻丰满熟妇久久久久久| 久久男人中文字幕资源站| 欧美久久久久久精选9999| 久久er热视频在这里精品| 色偷偷久久一区二区三区| 精品国产日韩久久亚洲| 久久久久99精品成人片三人毛片 | 一本一本久久aa综合精品| 亚洲午夜精品久久久久久app| 国产精品成人精品久久久| 精品国产乱码久久久久久1区2区| 久久国产色av免费看| 久久精品国产亚洲av麻豆小说| 久久久久亚洲AV无码麻豆| 久久99热这里只有精品国产| 久久青青草视频| 久久人做人爽一区二区三区| 99久久精品国产一区二区| 五月丁香综合激情六月久久| 亚洲乱码中文字幕久久孕妇黑人| 久久综合国产乱子伦精品免费|