久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='1T1U3'><tr id='1T1U3'><dt id='1T1U3'><q id='1T1U3'><span id='1T1U3'><b id='1T1U3'><form id='1T1U3'><ins id='1T1U3'></ins><ul id='1T1U3'></ul><sub id='1T1U3'></sub></form><legend id='1T1U3'></legend><bdo id='1T1U3'><pre id='1T1U3'><center id='1T1U3'></center></pre></bdo></b><th id='1T1U3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1T1U3'><tfoot id='1T1U3'></tfoot><dl id='1T1U3'><fieldset id='1T1U3'></fieldset></dl></div>
  • <tfoot id='1T1U3'></tfoot>

      <small id='1T1U3'></small><noframes id='1T1U3'>

        <legend id='1T1U3'><style id='1T1U3'><dir id='1T1U3'><q id='1T1U3'></q></dir></style></legend>
          <bdo id='1T1U3'></bdo><ul id='1T1U3'></ul>

        模板元編程 - 使用 Enum Hack 和 Static Const 的區別

        Template Metaprogramming - Difference Between Using Enum Hack and Static Const(模板元編程 - 使用 Enum Hack 和 Static Const 的區別)
        <legend id='oxE10'><style id='oxE10'><dir id='oxE10'><q id='oxE10'></q></dir></style></legend>
        • <bdo id='oxE10'></bdo><ul id='oxE10'></ul>

            <tfoot id='oxE10'></tfoot>
            • <small id='oxE10'></small><noframes id='oxE10'>

              <i id='oxE10'><tr id='oxE10'><dt id='oxE10'><q id='oxE10'><span id='oxE10'><b id='oxE10'><form id='oxE10'><ins id='oxE10'></ins><ul id='oxE10'></ul><sub id='oxE10'></sub></form><legend id='oxE10'></legend><bdo id='oxE10'><pre id='oxE10'><center id='oxE10'></center></pre></bdo></b><th id='oxE10'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oxE10'><tfoot id='oxE10'></tfoot><dl id='oxE10'><fieldset id='oxE10'></fieldset></dl></div>
                  <tbody id='oxE10'></tbody>

                  本文介紹了模板元編程 - 使用 Enum Hack 和 Static Const 的區別的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我想知道在使用模板元編程技術時使用靜態常量和枚舉黑客有什么區別.

                  I'm wondering what the difference is between using a static const and an enum hack when using template metaprogramming techniques.

                  EX:(斐波那契通過 TMP)

                  EX: (Fibonacci via TMP)

                  template< int n > struct TMPFib {
                    static const int val =
                      TMPFib< n-1 >::val + TMPFib< n-2 >::val;
                  };
                  
                  template<> struct TMPFib< 1 > {
                    static const int val = 1;
                  };
                  
                  template<> struct TMPFib< 0 > {
                    static const int val = 0;
                  };
                  

                  對比

                  template< int n > struct TMPFib {
                    enum {
                      val = TMPFib< n-1 >::val + TMPFib< n-2 >::val
                    };
                  };
                  
                  template<> struct TMPFib< 1 > {
                    enum { val = 1 };
                  };
                  
                  template<> struct TMPFib< 0 > {
                    enum { val = 0 };
                  };
                  

                  為什么要使用一個?我已經讀到在類內部支持靜態常量之前使用了 enum hack,但為什么現在使用它?

                  Why use one over the other? I've read that the enum hack was used before static const was supported inside classes, but why use it now?

                  推薦答案

                  枚舉不是 lval,靜態成員值是,如果通過引用傳遞模板將被實例化:

                  Enums aren't lvals, static member values are and if passed by reference the template will be instanciated:

                  void f(const int&);
                  f(TMPFib<1>::value);
                  

                  如果你想做純編譯時間計算等,這是一個不希望的副作用.

                  If you want to do pure compile time calculations etc. this is an undesired side-effect.

                  主要的歷史差異是枚舉也適用于不支持成員值的類內初始化的編譯器,現在大多數編譯器都應該修復這個問題.
                  枚舉和靜態常量的編譯速度也可能存在差異.

                  The main historic difference is that enums also work for compilers where in-class-initialization of member values is not supported, this should be fixed in most compilers now.
                  There may also be differences in compilation speed between enum and static consts.

                  boost 編碼指南和舊線程 在有關該主題的 boost 檔案中.

                  There are some details in the boost coding guidelines and an older thread in the boost archives regarding the subject.

                  這篇關于模板元編程 - 使用 Enum Hack 和 Static Const 的區別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Why do two functions have the same address?(為什么兩個函數的地址相同?)
                  Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復制構造的?)
                  mixing templates with polymorphism(混合模板與多態性)
                  When should I use the keyword quot;typenamequot; when using templates(我什么時候應該使用關鍵字“typename?使用模板時)
                  Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標準庫)
                  gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數模板,而 clang 不能)

                1. <tfoot id='ZVY9D'></tfoot>

                      <small id='ZVY9D'></small><noframes id='ZVY9D'>

                        <legend id='ZVY9D'><style id='ZVY9D'><dir id='ZVY9D'><q id='ZVY9D'></q></dir></style></legend>
                          <tbody id='ZVY9D'></tbody>
                      1. <i id='ZVY9D'><tr id='ZVY9D'><dt id='ZVY9D'><q id='ZVY9D'><span id='ZVY9D'><b id='ZVY9D'><form id='ZVY9D'><ins id='ZVY9D'></ins><ul id='ZVY9D'></ul><sub id='ZVY9D'></sub></form><legend id='ZVY9D'></legend><bdo id='ZVY9D'><pre id='ZVY9D'><center id='ZVY9D'></center></pre></bdo></b><th id='ZVY9D'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ZVY9D'><tfoot id='ZVY9D'></tfoot><dl id='ZVY9D'><fieldset id='ZVY9D'></fieldset></dl></div>
                          <bdo id='ZVY9D'></bdo><ul id='ZVY9D'></ul>

                            主站蜘蛛池模板: 香蕉婷婷| 国产一区不卡 | 国产成人精品一区二区三区在线观看 | 日产精品久久久一区二区福利 | 国产av毛片 | 国产一区二区三区色淫影院 | 精品视频网 | 亚洲精品乱码久久久久久蜜桃 | 亚洲激情自拍偷拍 | 久久精点视频 | 成人精品一区二区三区 | 欧美性久久 | 久久婷婷国产麻豆91 | 美女视频一区二区三区 | 91久久精品日日躁夜夜躁国产 | 欧美h| 在线看亚洲 | www九色| 97色在线观看免费视频 | 在线观看国产精品一区二区 | 欧美日韩成人网 | 亚洲精精品| 日韩区 | 国产精品视频综合 | 草久久| 国产高清在线 | 成人欧美一区二区 | 成人性视频免费网站 | 久久小视频 | 久久网站黄 | 国产成人艳妇aa视频在线 | 免费在线观看91 | 免费看的黄网站 | 日韩在线免费视频 | 91一区 | 国产福利在线视频 | 日韩一区二区三区在线播放 | 日韩精品一区二区三区中文在线 | 国产一级毛片视频 | 九九在线精品视频 | 91精品久久久久久久久 |