• <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
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(5)

            隨筆分類(38)

            隨筆檔案(31)

            收藏夾(4)

            College

            High School

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 55886
            • 排名 - 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 閱讀(1451) 評論(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太調皮了  回復  更多評論
              
            9191精品国产免费久久| 午夜欧美精品久久久久久久| 久久这里只有精品首页| 精品久久人人妻人人做精品 | 精品无码久久久久久午夜| 久久久久99精品成人片直播| 伊人久久综合热线大杳蕉下载| 久久久久久国产精品无码下载| 国产激情久久久久久熟女老人| 91精品国产色综合久久| 日本国产精品久久| 国产精品久久国产精品99盘| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 狠色狠色狠狠色综合久久| 一级女性全黄久久生活片免费| 亚洲国产欧美国产综合久久| 丁香五月综合久久激情| 一本久道久久综合狠狠爱| 久久久人妻精品无码一区| 久久精品免费观看| 亚洲精品国产美女久久久| 热综合一本伊人久久精品| 成人久久综合网| 国内精品综合久久久40p| 一97日本道伊人久久综合影院| 狠狠狠色丁香婷婷综合久久俺| 伊人久久大香线焦AV综合影院| 欧美精品一区二区久久| 国产一区二区精品久久岳| 欧美777精品久久久久网| 国产成人精品免费久久久久| 久久久久波多野结衣高潮| 久久人人添人人爽添人人片牛牛| 天天做夜夜做久久做狠狠| 久久免费香蕉视频| 国産精品久久久久久久| 久久91精品综合国产首页| 狠狠色丁香久久综合婷婷| 精品久久久无码人妻中文字幕豆芽| 无码国内精品久久人妻| 人妻少妇久久中文字幕|