久久久久久久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大片在线观看 | 久本草精品 | 五月天婷婷综合 | 中文字幕一区在线观看 | 视频爱爱免费视频爱爱太爽 | 少妇网址 | 三年中文在线看免费观看 | 久久久久久久免费视频 | 国产一级片免费观看 | 亚洲福利一区 | 97在线免费视频 | 婷婷丁香六月 | 精品国产乱码久久久久久蜜柚 | 日韩成人中文字幕 | 欧美在线视频一区二区 | 91黄色免费视频 | 日韩网站免费观看 | 国产做爰视频免费播放 | 国产日韩欧美精品 | 久久精品视频网 | 在线a | 四虎影院网站 | 亚洲欧美天堂 | 国产极品国产极品 | 欧洲色综合| 亚洲第一免费视频 | 国产精品一级二级 | 黄色国产片| 午夜激情网站 | 亚洲免费视频网站 | 色婷婷一区二区三区四区 | 欧美成在线| 久久久久久国产 | 色综合五月 | 国产精品嫩草影院桃色 | 四虎永久在线 | 国产精品99精品久久免费 | 久久午夜视频 | 天天干天天操天天射 |