pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="x7knqzc" 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="tiwrnsr" id='6WNPs'><tfoot id='6WNPs'></tfoot><dl id='6WNPs'><fieldset id='6WNPs'></fieldset></dl></div>

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

                  問題描述

                  限時(shí)送ChatGPT賬號..

                  我正在閱讀一些名為 C++11 和 C++14 概述,由 Leor Zolman 先生提出.在第 35 頁,他介紹了一種使用 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)然,如果沒有對返回類型進(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è)簡單轉(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 不能的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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)庫)
                  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="yhkilvt" 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>

                            主站蜘蛛池模板: IWIS链条代理-ALPS耦合透镜-硅烷预处理剂-上海顶楚电子有限公司 lcd条形屏-液晶长条屏-户外广告屏-条形智能显示屏-深圳市条形智能电子有限公司 | LED灯杆屏_LED广告机_户外LED广告机_智慧灯杆_智慧路灯-太龙智显科技(深圳)有限公司 | 智能型高压核相仪-自动开口闪点测试仪-QJ41A电雷管测试仪|上海妙定 | 电磁铁_推拉电磁铁_机械手电磁吸盘电磁铁厂家-广州思德隆电子公司 | 天津仓库出租网-天津电商仓库-天津云仓一件代发-【博程云仓】 | 安徽净化板_合肥岩棉板厂家_玻镁板厂家_安徽科艺美洁净科技有限公司 | 自动螺旋上料机厂家价格-斗式提升机定制-螺杆绞龙输送机-杰凯上料机 | 纯化水设备-EDI-制药-实验室-二级反渗透-高纯水|超纯水设备 | 食品质构分析仪-氧化诱导分析仪-瞬态法导热系数仪|热冰百科 | Win10系统下载_32位/64位系统/专业版/纯净版下载 | 台湾阳明固态继电器-奥托尼克斯光电传感器-接近开关-温控器-光纤传感器-编码器一级代理商江苏用之宜电气 | 压装机-卧式轴承轮轴数控伺服压装机厂家[铭泽机械] | 广州中央空调回收,二手中央空调回收,旧空调回收,制冷设备回收,冷气机组回收公司-广州益夫制冷设备回收公司 | 冷却塔厂家_冷却塔维修_冷却塔改造_凉水塔配件填料公司- 广东康明节能空调有限公司 | 合金ICP光谱仪(磁性材料,工业废水)-百科 | 铆钉机|旋铆机|东莞旋铆机厂家|鸿佰专业生产气压/油压/自动铆钉机 | 伺服电机维修、驱动器维修「安川|三菱|松下」伺服维修公司-深圳华创益 | 铝合金风口-玻璃钢轴流风机-玻璃钢屋顶风机-德州东润空调设备有限公司 | 水厂自动化-水厂控制系统-泵站自动化|控制系统-闸门自动化控制-济南华通中控科技有限公司 | 深圳市东信高科自动化设备有限公司 | 废气处理设备-工业除尘器-RTO-RCO-蓄热式焚烧炉厂家-江苏天达环保设备有限公司 | 德国BOSCH电磁阀-德国HERION电磁阀-JOUCOMATIC电磁阀|乾拓百科 | 刑事律师_深圳著名刑事辩护律师_王平聚【清华博士|刑法教授】 | 大数据营销公司_舆情监测软件_上海SEO公司-文军营销官网 | 火锅加盟_四川成都火锅店加盟_中国火锅连锁品牌十强_朝天门火锅【官网】 | 无锡网站建设_小程序制作_网站设计公司_无锡网络公司_网站制作 | 塑料造粒机「厂家直销」-莱州鑫瑞迪机械有限公司 | 档案密集架_电动密集架_移动密集架_辽宁档案密集架-盛隆柜业厂家现货批发销售价格公道 | 润滑脂-高温润滑脂-轴承润滑脂-食品级润滑油-索科润滑油脂厂家 | 滚珠丝杆升降机_螺旋升降机_丝杠升降机-德迈传动 | 翅片管散热器价格_钢制暖气片报价_钢制板式散热器厂家「河北冀春暖气片有限公司」 | 中山市派格家具有限公司【官网】 | 空冷器|空气冷却器|空水冷却器-无锡赛迪森机械有限公司[官网] | 物流之家新闻网-最新物流新闻|物流资讯|物流政策|物流网-匡匡奈斯物流科技 | BAUER减速机|ROSSI-MERSEN熔断器-APTECH调压阀-上海爱泽工业设备有限公司 | 减速机_上海宜嘉减速机| vr安全体验馆|交通安全|工地安全|禁毒|消防|安全教育体验馆|安全体验教室-贝森德(深圳)科技 | 北京发电车出租-发电机租赁公司-柴油发电机厂家 - 北京明旺盛安机电设备有限公司 | 东莞市海宝机械有限公司-不锈钢分选机-硅胶橡胶-生活垃圾-涡电流-静电-金属-矿石分选机 | 电竞馆加盟,沈阳网吧加盟费用选择嘉棋电竞_售后服务一体化 | 政府回应:200块在义乌小巷能买到爱情吗?——揭秘打工族省钱约会的生存智慧 |