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

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

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

        gcc 可以編譯可變參數模板,而 clang 不能

        gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數模板,而 clang 不能)

            <bdo id='6WNPs'></bdo><ul id='6WNPs'></ul>
              <tbody id='6WNPs'></tbody>

              <small id='6WNPs'></small><noframes id='6WNPs'>

              <tfoot id='6WNPs'></tfoot>
              • <legend id='6WNPs'><style id='6WNPs'><dir id='6WNPs'><q id='6WNPs'></q></dir></style></legend>

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

                • 本文介紹了gcc 可以編譯可變參數模板,而 clang 不能的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在閱讀一些名為 C++11 和 C++14 概述,由 Leor Zolman 先生提出.在第 35 頁,他介紹了一種使用 decltype 進行求和運算的方法.

                  I'm reading some slides named An Overview of C++11 and C++14 presented by Mr. Leor Zolman. At Page 35 he introduces a way to do the sum operation with decltype.

                  struct Sum {
                    template <typename T>
                    static T sum(T n) {
                      return n;
                    }
                    template <typename T, typename... Args>
                    /// static T sum(T n, Args... rest) {
                    static auto sum(T n, Args... rest) -> decltype(n + sum(rest...)) {
                      return n + sum(rest...);
                    }
                  };
                  

                  當為Sum::sum(1, 2.3, 4, 5); 使用這個片段時,clang-3.6(from svn) 無法用 -std=c++ 編譯它11/-std=c++1y 但 gcc-4.9 成功了.當然,如果沒有對返回類型進行類型推導,兩者都可以編譯,但這涉及類型轉換,無法得到預期的結果.

                  When using this snippets forSum::sum(1, 2.3, 4, 5); clang-3.6(from svn) fails to compile this with -std=c++11/-std=c++1y but gcc-4.9 succeeds. Of course without type deduction for the return type both compile, but that involves type conversion and cannot get the expected result.

                  那么這是否表示一個 clang 錯誤,或者是因為 gcc 擴展(就 c++11 或 c++14 而言)?

                  So does this indicate a clang bug, or is because of a gcc extension(in respect of c++11 or c++14)?

                  推薦答案

                  Clang 的行為是正確的.這是一個 GCC 錯誤(并且演示文稿中的聲明也不正確).§3.3.2 [basic.scope.pdecl]/p1,6:

                  Clang's behavior is correct. This is a GCC bug (and the claim in the presentation is also incorrect). §3.3.2 [basic.scope.pdecl]/p1,6:

                  1 名稱的聲明點緊隨其后完整的聲明符(第 8 條)及其初始化程序(如果有)之前,除非如下所述.

                  1 The point of declaration for a name is immediately after its complete declarator (Clause 8) and before its initializer (if any), except as noted below.

                  6 類成員聲明點后,成員名可以在其類的范圍內查找.

                  6 After the point of declaration of a class member, the member name can be looked up in the scope of its class.

                  第 3.3.7 節 [basic.scope.class]/p1 說

                  And §3.3.7 [basic.scope.class]/p1 says

                  以下規則描述了在類中聲明的名稱的范圍.

                  The following rules describe the scope of names declared in classes.

                  1) 在類中聲明的名稱的潛在范圍不僅包括名稱聲明點之后的聲明區域,還有所有的函數體,默認參數,exception-specificationsbrace-or-equal-initializers該類中的非靜態數據成員(包括嵌套類).

                  1) The potential scope of a name declared in a class consists not only of the declarative region following the name’s point of declaration, but also of all function bodies, default arguments, exception-specifications, and brace-or-equal-initializers of non-static data members in that class (including such things in nested classes).

                  trailing-return-types 不在該列表中.

                  尾隨返回類型是聲明符的一部分 (§8 [dcl.decl]/p4):

                  The trailing return type is part of the declarator (§8 [dcl.decl]/p4):

                  declarator:
                      ptr-declarator
                      noptr-declarator parameters-and-qualifiers trailing-return-type
                  

                  因此 sum 的可變參數版本不在其自己的trailing-return-type 范圍內,并且無法通過名稱查找找到.

                  and so the variadic version of sum isn't in scope within its own trailing-return-type and cannot be found by name lookup.

                  在 C++14 中,只需使用實際返回類型推導(并省略尾隨返回類型).在 C++11 中,你可以使用一個類模板和一個簡單轉發的函數模板:

                  In C++14, simply use actual return type deduction (and omit the trailing return type). In C++11, you may use a class template instead and a function template that simply forwards:

                  template<class T, class... Args>
                  struct Sum {
                      static auto sum(T n, Args... rest) -> decltype(n + Sum<Args...>::sum(rest...)) {
                          return n + Sum<Args...>::sum(rest...);
                      }
                  };
                  
                  template<class T>
                  struct Sum<T>{
                      static T sum(T n) { return n; }
                  };
                  
                  template<class T, class... Args>
                  auto sum(T n, Args... rest) -> decltype(Sum<T, Args...>::sum(n, rest...)){
                      return Sum<T, Args...>::sum(n, rest...);
                  }
                  

                  這篇關于gcc 可以編譯可變參數模板,而 clang 不能的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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/標準庫)
                  Strong typedefs(強類型定義)

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

                    <tbody id='wU6rC'></tbody>

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

                            主站蜘蛛池模板: 免费看啪啪网站 | 日日艹夜夜艹 | 国产99久久 | 久久久在线视频 | 高清色视频| 2019天天干夜夜操 | 欧美精品日韩精品 | 粉嫩高清一区二区三区 | 精品美女在线观看视频在线观看 | 日本高清不卡视频 | 美女天天操| 国产亚洲精品久久久久久牛牛 | www日韩高清 | 一级中国毛片 | 国产激情亚洲 | 日韩欧美高清dvd碟片 | av日日操 | 成人免费三级电影 | 色一级片| 国产一级片一区二区 | 蜜桃在线一区二区三区 | 欧美精品一区二区三区在线 | 99亚洲精品 | 日韩av免费看 | 在线国产一区二区三区 | 一区二区三区播放 | 精产国产伦理一二三区 | 成人亚洲片 | a级在线 | 日韩成人av在线 | 日韩欧美国产精品一区二区 | 日韩高清国产一区在线 | 四虎永久免费在线 | 久久er99热精品一区二区 | 99精品久久久 | 国产欧美精品一区二区三区 | 成人av免费播放 | 久久精品成人 | 99精品一区二区三区 | 亚洲国产成人精品久久久国产成人一区 | 四虎影视在线 |