久久久久久久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 可以編譯可變參數(shù)模板,而 clang 不能

        gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數(shù)模板,而 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 可以編譯可變參數(shù)模板,而 clang 不能的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時(shí)送ChatGPT賬號(hào)..

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

                  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...);
                    }
                  };
                  

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

                  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.

                  那么這是否表示一個(gè) clang 錯(cuò)誤,或者是因?yàn)?gcc 擴(kuò)展(就 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 的行為是正確的.這是一個(gè) GCC 錯(cuò)誤(并且演示文稿中的聲明也不正確).§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 名稱的聲明點(diǎn)緊隨其后完整的聲明符(第 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 類成員聲明點(diǎn)后,成員名可以在其類的范圍內(nèi)查找.

                  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 節(jié) [basic.scope.class]/p1 說

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

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

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

                  1) 在類中聲明的名稱的潛在范圍不僅包括名稱聲明點(diǎn)之后的聲明區(qū)域,還有所有的函數(shù)體,默認(rèn)參數(shù),exception-specificationsbrace-or-equal-initializers該類中的非靜態(tài)數(shù)據(jù)成員(包括嵌套類).

                  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 的可變參數(shù)版本不在其自己的trailing-return-type 范圍內(nèi),并且無法通過名稱查找找到.

                  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 中,只需使用實(shí)際返回類型推導(dǎo)(并省略尾隨返回類型).在 C++11 中,你可以使用一個(gè)類模板和一個(gè)簡(jiǎn)單轉(zhuǎn)發(fā)的函數(shù)模板:

                  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...);
                  }
                  

                  這篇關(guān)于gcc 可以編譯可變參數(shù)模板,而 clang 不能的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Why do two functions have the same address?(為什么兩個(gè)函數(shù)的地址相同?)
                  Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復(fù)制構(gòu)造的?)
                  mixing templates with polymorphism(混合模板與多態(tài)性)
                  When should I use the keyword quot;typenamequot; when using templates(我什么時(shí)候應(yīng)該使用關(guān)鍵字“typename?使用模板時(shí))
                  Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標(biāo)準(zhǔn)庫(kù))
                  Strong typedefs(強(qiáng)類型定義)

                  <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>

                            主站蜘蛛池模板: 午夜免费剧场 | 日本国产精品 | 国产欧美日韩综合精品 | 国产精品视频久久 | 免费毛片网站 | 天堂中文资源在线 | 国产精品国产精品国产专区不片 | 91porn在线| 狠狠做深爱婷婷久久综合一区 | 色播五月婷婷 | 日韩黄色影院 | 国产精品偷乱一区二区三区 | 激情婷婷丁香 | 国产成人在线免费视频 | 欧美爱爱视频 | 亚洲欧美一区二区三区在线 | 就爱啪啪网 | 91成人在线观看喷潮 | 四虎影院免费观看 | 激情综合网五月 | 久久狠 | 日韩免费视频一区二区 | 中国黄色1级片 | 一区二区三区精品 | 亚洲综合国产 | 国产激情一区二区三区 | 国产乱码一区二区三区 | 午夜免费影院 | 99热| 黄色激情视频网站 | 日韩在线中文 | 一区中文字幕 | 亚洲做受高潮无遮挡 | 亚洲一区二区在线视频 | 日皮视频免费看 | 日韩精品在线观看视频 | 欧美在线网址 | 国产午夜精品久久 | 色中色综合 | 日韩成人中文字幕 | 国产福利在线视频 |