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

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

      1. <small id='iDB53'></small><noframes id='iDB53'>

        我能在模板參數中聲明一個 constexpr lambda 嗎?

        Will I be able to declare a constexpr lambda inside a template parameter?(我能在模板參數中聲明一個 constexpr lambda 嗎?)
        • <bdo id='N48dz'></bdo><ul id='N48dz'></ul>
          <tfoot id='N48dz'></tfoot>
          <legend id='N48dz'><style id='N48dz'><dir id='N48dz'><q id='N48dz'></q></dir></style></legend>
            <tbody id='N48dz'></tbody>

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

                  <i id='N48dz'><tr id='N48dz'><dt id='N48dz'><q id='N48dz'><span id='N48dz'><b id='N48dz'><form id='N48dz'><ins id='N48dz'></ins><ul id='N48dz'></ul><sub id='N48dz'></sub></form><legend id='N48dz'></legend><bdo id='N48dz'><pre id='N48dz'><center id='N48dz'></center></pre></bdo></b><th id='N48dz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='N48dz'><tfoot id='N48dz'></tfoot><dl id='N48dz'><fieldset id='N48dz'></fieldset></dl></div>
                  本文介紹了我能在模板參數中聲明一個 constexpr lambda 嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我知道這就像打開潘多拉盒子,但它并沒有停止打擾我.考慮一個簡單的例子:

                  I know it's like opening the Pandora box but it doesn't stop bothering me. Consider a simple example:

                  #include <type_traits>
                  
                  template <auto>
                  struct Foo: std::false_type { };
                  
                  template <>
                  struct Foo<[](){return 1;}()>:std::true_type { };
                  
                  int main() {
                      static_assert(Foo<1>::value);
                  }
                  

                  我知道 lambdas 不能在未評估的上下文中聲明,但顯然這里不是這種情況.還有什么更奇怪的 clang 5.0.0(我猜它首先部分支持 constexpr lambda)編譯它.

                  I know lambdas cannot be declared inside unevaluated context, but obviously this is not the case here. What is even more weird clang 5.0.0 (which, I guess, first partially supports constexpr lambda) does compile it.

                  這是編譯器錯誤還是 C++17 允許這樣做?

                  Is it a compiler bug or will C++17 allow this?

                  推薦答案

                  不,這是一個編譯器錯誤.gcc 7.1 正確拒絕代碼.

                  No, that is a compiler bug. gcc 7.1 correctly rejects the code.

                  [expr.prim.lambda]/2:

                  lambda 表達式是一個純右值,其結果對象稱為閉包對象.lambda 表達式不得出現在未求值的操作數、模板參數、別名聲明、typedef 聲明或函數聲明中或函數體外的函數模板聲明中和默認參數.

                  A lambda-expression is a prvalue whose result object is called the closure object. A lambda-expression shall not appear in an unevaluated operand, in a template-argument, in an alias-declaration, in a typedef declaration, or in the declaration of a function or function template outside its function body and default arguments.

                  從我標記為粗體的部分可以看出,lambda 表達式不能出現在模板參數列表中.

                  As you can see from the part that I marked as bold, a lambda expression cannot appear in a template argument list.

                  這在隨后的注釋中也有明確說明:

                  This is also made clear in a subsequent note:

                  [ 注意:目的是防止 lambda 出現在簽名中.— 尾注 ]

                  [?Note: The intention is to prevent lambdas from appearing in a signature. —?end note?]

                  如果我猜的話,我會說這個錯誤是因為從 C++17 開始,lambdas 是隱式的 constexpr,這使得它們在編譯時表達式中被調用是有效的,比如模板參數.但實際上在模板參數中定義 lambda 仍然是非法的.

                  If I were to guess, I would say that the bug comes about because starting with C++17, lambdas are implicitly constexpr, which makes them valid to be called in compile time expressions, like template arguments. But actually defining a lambda in a template argument is still illegal.

                  請注意,此限制已在 C++20 中取消.:)

                  Note that this restriction has been lifted in C++20. :)

                  這篇關于我能在模板參數中聲明一個 constexpr lambda 嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)

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

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

                            <tbody id='aca05'></tbody>
                            主站蜘蛛池模板: 欧美一区免费 | 成人精品免费视频 | 成人免费看黄网站在线观看 | 欧美一级片免费看 | 中文字幕成人在线 | 一区精品在线观看 | 在线日韩 | 成人国产在线观看 | 91视频精选 | 亚洲成人免费电影 | jlzzjlzz欧美大全| 国精日本亚洲欧州国产中文久久 | 亚洲91精品| 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 一区二区免费看 | 黑人一级片视频 | 久久久91精品国产一区二区三区 | 欧美亚洲视频 | 另类亚洲视频 | 欧美日韩国产一区二区三区 | 精品国产精品三级精品av网址 | 国产精品一区二区三区久久久 | 国产成人在线视频 | 欧美日韩精品一区 | 中文字幕色站 | 免费久久久久久 | 成人午夜在线视频 | 九九久久久| 亚洲精品大片 | 日本黄色大片免费看 | 国产高清免费 | 怡红院免费的全部视频 | 大陆一级毛片免费视频观看 | 欧美精品一区二区免费视频 | 岛国av免费在线观看 | 亚洲精品99 | 久久久久久久一区 | .国产精品成人自产拍在线观看6 | 99精品国产一区二区三区 | 天天欧美| 精品中文字幕在线观看 |