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

      <tfoot id='TVE6H'></tfoot>
      • <bdo id='TVE6H'></bdo><ul id='TVE6H'></ul>

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

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

    2. <legend id='TVE6H'><style id='TVE6H'><dir id='TVE6H'><q id='TVE6H'></q></dir></style></legend>

      如何使用 lambda 表達式作為模板參數?

      How to use a lambda expression as a template parameter?(如何使用 lambda 表達式作為模板參數?)
      <tfoot id='FrASk'></tfoot>

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

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

            1. <legend id='FrASk'><style id='FrASk'><dir id='FrASk'><q id='FrASk'></q></dir></style></legend>
                <tbody id='FrASk'></tbody>
                <bdo id='FrASk'></bdo><ul id='FrASk'></ul>
                本文介紹了如何使用 lambda 表達式作為模板參數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                如何使用 lambda 表達式作為模板參數?例如.作為初始化 std::set 的比較類.

                How to use lambda expression as a template parameter? E.g. as a comparison class initializing a std::set.

                以下解決方案應該有效,因為 lambda 表達式僅創建一個匿名結構,它應該適合作為模板參數.然而,產生了很多錯誤.

                The following solution should work, as lambda expression merely creates an anonymous struct, which should be appropriate as a template parameter. However, a lot of errors are spawned.

                代碼示例:

                struct A {int x; int y;};
                std::set <A, [](const A lhs, const A &rhs) ->bool {
                    return lhs.x < rhs.x;
                    } > SetOfA;
                

                錯誤輸出(我使用的是 g++ 4.5.1 編譯器和 --std=c++0x 編譯標志):

                Error output (I am using g++ 4.5.1 compiler and --std=c++0x compilation flag):

                error: ‘lhs’ cannot appear in a constant-expression
                error: ‘.’ cannot appear in a constant-expression
                error: ‘rhs’ cannot appear in a constant-expression
                error: ‘.’ cannot appear in a constant-expression
                At global scope:
                error: template argument 2 is invalid
                

                這是預期的行為還是 GCC 中的錯誤?

                Is that the expected behavior or a bug in GCC?

                編輯

                正如有人指出的那樣,我錯誤地使用了 lambda 表達式,因為它們返回了他們所指的匿名結構的實例.

                As someone pointed out, I'm using lambda expressions incorrectly as they return an instance of the anonymous struct they are referring to.

                但是,修復該錯誤并不能解決問題.對于以下代碼,我在未評估的上下文中收到 lambda-expression 錯誤:

                However, fixing that error does not solve the problem. I get lambda-expression in unevaluated context error for the following code:

                struct A {int x; int y;};
                typedef decltype ([](const A lhs, const A &rhs) ->bool {
                    return lhs.x < rhs.x;
                    }) Comp;
                std::set <A, Comp > SetOfA;
                

                推薦答案

                std::set 的第二個模板參數需要 type,而不是 表達式,所以只是你用錯了.

                The 2nd template parameter of std::set expects a type, not an expression, so it is just you are using it wrongly.

                您可以像這樣創建集合:

                You could create the set like this:

                auto comp = [](const A& lhs, const A& rhs) -> bool { return lhs.x < rhs.x; };
                auto SetOfA = std::set <A, decltype(comp)> (comp);
                

                這篇關于如何使用 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 不能)
                  <tbody id='NYrbP'></tbody>

                  <tfoot id='NYrbP'></tfoot>

                  • <bdo id='NYrbP'></bdo><ul id='NYrbP'></ul>

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

                          <legend id='NYrbP'><style id='NYrbP'><dir id='NYrbP'><q id='NYrbP'></q></dir></style></legend>
                          主站蜘蛛池模板: 快播少女爱欢乐 | 成人一区二区三区在线 | 久久小视频 | 成人综合婷婷国产精品久久 | 久久精品视频网 | 国产在线一区二区三区 | 欧美一区视频 | 国产a视频 | 精品免费观看 | aaa黄色片 | 欧美日韩亚洲一区二区 | 99热亚洲 | 在线视频h | 久久精品欧美一区二区 | 国产精品国产精品国产专区不片 | 国产午夜精品视频 | 免费网站www| www.久草 | 全部免费毛片在线播放高潮 | 国产精品永久久久久久久久久 | 五月天激情国产综合婷婷婷 | 国产成人免费在线观看 | 三级在线观看视频 | 91久久久精品| 五月婷婷网 | 国产免费一级片 | 国产精品久久久久久久成人午夜 | 午夜国产视频 | 国产精品久久久久久久久久久久午夜片 | 美女黄色在线观看 | 可以看毛片的网站 | 99这里有精品 | 午夜激情影视 | 日本一区二区不卡视频 | 天天操网 | 亚洲三级小说 | 欧美亚洲一区 | 久久久免费观看 | 精品久久久久久 | 国产成人精品一区 | 黄色小说网站在线观看 |