• <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>
            隨筆 - 31  文章 - 128  trackbacks - 0
            <2008年1月>
            303112345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            常用鏈接

            留言簿(5)

            隨筆分類(38)

            隨筆檔案(31)

            收藏夾(4)

            College

            High School

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 55896
            • 排名 - 407

            最新評論

            • 1.?re: [yc]詳解link
            • 面試的時候面試官就問過我什么是編譯和鏈接,我說編譯就是把代碼文件生成目標文件,鏈接就是把目標文件生成可執行文件,他說不對,又問我什么是動態鏈接,還問我預編譯都做什么處理。。。都在這里找到了答案!!!!
            • --王至乾
            • 2.?re: [yc]詳解link
            • @劉偉
              我是說博主,不是叫你啊
            • --溪流
            • 3.?re: [yc]詳解link
            • 誰是石老師,我不是哈@溪流
            • --劉偉
            • 4.?re: [yc]詳解link
            • 石老師?我是溪流~
            • --溪流
            • 5.?re: [yc]詳解link
            • 期待樓主下文啊,多謝樓主了
            • --劉偉

            閱讀排行榜

            評論排行榜

            boost的integer/integer_mask.hpp僅僅做了單個位的bit mask
            要多個位必須寫很多遍high_bit_mask_t
            使用low_bits_mask_t也不能完全解決問題
            所以自己用Typelist的那種寫法寫了一個

            用法舉例
            bit_mask<INT_LIST_2(2, 3)>::value返回一個值,該值的第2、3位被置為1
            其余位為0

             

              1 
              2 namespace multi_bit_mask
              3 {
              4     namespace details
              5     {
              6 
              7         template <typename T>
              8         struct get_size
              9         {
             10             enum {size = sizeof(T)}; 
             11         };
             12 
             13         template <int Bit>
             14         struct bit_storage
             15         {
             16             typedef typename bit_storage<Bit - 1>::storage_type storage_type;
             17         };
             18 
             19         //---------platform dependency-----------------------
             20 
             21         typedef unsigned int smallest_storage_type;
             22         typedef unsigned long long largest_storage_type;
             23 
             24         
             25 
             26         template <>
             27         struct bit_storage<0>
             28         {
             29             typedef smallest_storage_type storage_type;
             30         };
             31 
             32         template <>
             33         struct bit_storage<get_size<smallest_storage_type>::size * 8>
             34         {
             35             typedef largest_storage_type storage_type;
             36         };
             37 
             38         //disable the 65th bit
             39         template <>
             40         struct bit_storage<get_size<largest_storage_type>::size * 8>
             41         {
             42             typedef void storage_type;
             43         };
             44         
             45         //---------end of platform dependency----------------
             46 
             47 
             48         template <unsigned int N, typename Next>
             49         struct int_list
             50         {
             51             typedef typename bit_storage<N>::storage_type storage_type;
             52             static const storage_type value = N;
             53             typedef Next next;
             54         };
             55 
             56         struct null_type{};
             57 
             58         template<typename T1, typename T2, bool is_first>
             59         struct selector
             60         {
             61             typedef T1 type;
             62         };
             63 
             64         template<typename T1, typename T2>
             65         struct compare_type
             66         {
             67             const static bool is_larger = sizeof(T1) > sizeof(T2);
             68             typedef typename selector<T1, T2, is_larger>::type large_type;
             69             typedef typename selector<T1, T2, !is_larger>::type small_type;
             70         };
             71 
             72 
             73 
             74         template<typename T1, typename T2>
             75         struct selector<T1, T2, false>
             76         {
             77             typedef T2 type;
             78         };
             79 
             80         template <typename List>
             81         class find_largest_storage
             82         {
             83             typedef typename find_largest_storage<typename List::next>::storage_type T1;
             84             typedef typename bit_storage<List::value>::storage_type T2;
             85         public:
             86             typedef typename compare_type<T1, T2>::large_type storage_type;
             87         };
             88 
             89         template <>
             90         class find_largest_storage<null_type>
             91         {
             92         public:
             93             typedef smallest_storage_type storage_type;
             94         };    
             95 
             96         
             97     }
             98 
             99 
            100         
            101 
            102 
            103     template <int N>
            104     struct single_bit_mask
            105     {
            106         typedef typename details::bit_storage<N>::storage_type storage_type;
            107         static const storage_type value 
            108             = static_cast<storage_type>(single_bit_mask<- 1>::value) * 2;
            109     };
            110 
            111     template <>
            112     struct single_bit_mask<0>
            113     {
            114         typedef details::bit_storage<0>::storage_type storage_type;
            115         static const storage_type value = 1;
            116     };
            117 
            118     
            119     typedef details::null_type null_type;
            120 
            121     template <int N, typename Next>
            122     struct int_list_t : public details::int_list<N, Next> {};
            123 
            124     template <typename List>
            125     struct bit_mask
            126     {
            127     public:
            128 
            129         typedef typename details::find_largest_storage<List>::storage_type storage_type;
            130     
            131         static const storage_type value 
            132             = static_cast<storage_type>(single_bit_mask<List::value>::value) 
            133             | static_cast<storage_type>(bit_mask<typename List::next>::value);
            134     };
            135 
            136     template <>
            137     struct bit_mask<null_type>
            138     {
            139         typedef details::bit_storage<0>::storage_type storage_type;
            140         static const storage_type value = 0;
            141     };
            142 
            143     
            144 
            145     
            146 
            147     #define INT_LIST_1(n1) multi_bit_mask::int_list_t<n1, multi_bit_mask::null_type>
            148     #define INT_LIST_2(n1, n2) multi_bit_mask::int_list_t<n1, INT_LIST_1(n2) > 
            149     #define INT_LIST_3(n1, n2, n3) multi_bit_mask::int_list_t<n1, INT_LIST_2(n2, n3) > 
            150     #define INT_LIST_4(n1, n2, n3, n4) multi_bit_mask::int_list_t<n1, INT_LIST_3(n2, n3, n4) > 
            151     #define INT_LIST_5(n1, n2, n3, n4, n5) multi_bit_mask::int_list_t<n1, INT_LIST_4(n2, n3, n4, n5) > 
            152     #define INT_LIST_6(n1, n2, n3, n4, n5, n6) multi_bit_mask::int_list_t<n1, INT_LIST_5(n2, n3, n4, n5, n6) > 
            153     #define INT_LIST_7(n1, n2, n3, n4, n5, n6, n7) multi_bit_mask::int_list_t<n1, INT_LIST_6(n2, n3, n4, n5, n6, n7) > 
            154     #define INT_LIST_8(n1, n2, n3, n4, n5, n6, n7, n8) multi_bit_mask::int_list_t<n1, INT_LIST_7(n2, n3, n4, n5, n6, n7, n8) > 
            155     
            156 }
            157 
            158 
            159 


            sample

            #include  < iostream >
            #include 
            " multi_bit_mask.h "
            using   namespace  std;
            int  main()
            {
                cout 
            <<  multi_bit_mask::bit_mask < INT_LIST_1( 1 ) > ::value  <<  endl;
                cout 
            <<  multi_bit_mask::bit_mask < INT_LIST_5( 0 1 2 3 4 ) > ::value  <<  endl;
                cout 
            <<  multi_bit_mask::bit_mask < INT_LIST_7( 0 1 2 3 4 4 2 ) > ::value  <<  endl;
                
            posted on 2006-10-26 23:37 shifan3 閱讀(1452) 評論(2)  編輯 收藏 引用 所屬分類: templateC++

            FeedBack:
            # re: Multi Bit Mask 2006-10-28 10:40 Windreamer
            禁止你BS我!

            我得先把自己賣了再來玩兒

            另,你那個platform dependency的常量可不可以用sizeof的
            ???????  回復  更多評論
              
            # re: Multi Bit Mask 2006-10-28 16:06 Francis Arcanum
            可以,但是還是不能保證什么
            主要是int太調皮了  回復  更多評論
              
            99热都是精品久久久久久| 亚洲va中文字幕无码久久| AAA级久久久精品无码区| 色综合久久久久| 久久久久久久久久久久中文字幕| 久久国产精品偷99| 麻豆av久久av盛宴av| 国内精品免费久久影院| 香港aa三级久久三级老师2021国产三级精品三级在 | 国产精品久久久久久久久软件| 久久精品国产亚洲av麻豆蜜芽 | 久久精品中文字幕有码| 婷婷久久香蕉五月综合加勒比| 久久久青草久久久青草| 亚洲精品无码久久千人斩| 久久久久免费视频| 久久综合九色综合97_久久久| 中文字幕久久精品| 日韩美女18网站久久精品| 国产成年无码久久久久毛片| 成人免费网站久久久| 999久久久国产精品| 久久国产美女免费观看精品 | 精品国产99久久久久久麻豆| 日韩亚洲欧美久久久www综合网| 亚洲国产精品无码久久SM| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 热久久国产精品| 国产精品免费福利久久| 亚洲日韩中文无码久久| 国产精品一区二区久久国产| 色天使久久综合网天天| 久久精品人人做人人爽电影| 欧美午夜A∨大片久久 | 久久精品无码一区二区无码| 久久婷婷色综合一区二区| 日本亚洲色大成网站WWW久久| 久久青青草原精品国产软件| 久久久国产打桩机| 亚洲国产精品无码久久一区二区| 久久99精品久久久大学生|