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

<legend id='KLTGA'><style id='KLTGA'><dir id='KLTGA'><q id='KLTGA'></q></dir></style></legend>

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

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

        <bdo id='KLTGA'></bdo><ul id='KLTGA'></ul>
      <tfoot id='KLTGA'></tfoot>

        為什么使用 std::forward 禁用模板參數推導?

        Why is template argument deduction disabled with std::forward?(為什么使用 std::forward 禁用模板參數推導?)

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

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

            • <tfoot id='EGwDq'></tfoot>
                  <legend id='EGwDq'><style id='EGwDq'><dir id='EGwDq'><q id='EGwDq'></q></dir></style></legend>
                1. 本文介紹了為什么使用 std::forward 禁用模板參數推導?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  在 VS2010 中 std::forward 定義如下:

                  In VS2010 std::forward is defined as such:

                  template<class _Ty> inline
                  _Ty&& forward(typename identity<_Ty>::type& _Arg)
                  {   // forward _Arg, given explicitly specified type parameter
                      return ((_Ty&&)_Arg);
                  }
                  

                  identity 似乎僅用于禁用模板參數推導.在這種情況下故意禁用它有什么意義?

                  identity appears to be used solely to disable template argument deduction. What's the point of purposefully disabling it in this case?

                  推薦答案

                  如果將 X 類型的對象的右值引用傳遞給采用 T&& 類型的模板函數 作為其參數,模板參數推導推導出 TX.因此,參數的類型為 X&&.如果函數參數是左值或 const 左值,則編譯器將其類型推導為該類型的左值引用或 const 左值引用.

                  If you pass an rvalue reference to an object of type X to a template function that takes type T&& as its parameter, template argument deduction deduces T to be X. Therefore, the parameter has type X&&. If the function argument is an lvalue or const lvalue, the compiler deduces its type to be an lvalue reference or const lvalue reference of that type.

                  如果 std::forward 使用模板參數推導:

                  If std::forward used template argument deduction:

                  由于帶有名稱的對象是左值,因此std::forward 唯一一次正確地轉換為T&&參數是一個未命名的右值(如 7func()).在完美轉發的情況下,您傳遞給 std::forwardarg 是一個左值,因為它有一個名稱.std::forward 的類型將被推導出為左值引用或常量左值引用.引用折疊規則將導致 std::forward 中 static_cast 中的 T&& 始終解析為左值引用或常量左值引用.

                  Since objects with names are lvalues the only time std::forward would correctly cast to T&& would be when the input argument was an unnamed rvalue (like 7 or func()). In the case of perfect forwarding the arg you pass to std::forward is an lvalue because it has a name. std::forward's type would be deduced as an lvalue reference or const lvalue reference. Reference collapsing rules would cause the T&& in static_cast<T&&>(arg) in std::forward to always resolve as an lvalue reference or const lvalue reference.

                  示例:

                  template<typename T>
                  T&& forward_with_deduction(T&& obj)
                  {
                      return static_cast<T&&>(obj);
                  }
                  
                  void test(int&){}
                  void test(const int&){}
                  void test(int&&){}
                  
                  template<typename T>
                  void perfect_forwarder(T&& obj)
                  {
                      test(forward_with_deduction(obj));
                  }
                  
                  int main()
                  {
                      int x;
                      const int& y(x);
                      int&& z = std::move(x);
                  
                      test(forward_with_deduction(7));    //  7 is an int&&, correctly calls test(int&&)
                      test(forward_with_deduction(z));    //  z is treated as an int&, calls test(int&)
                  
                      //  All the below call test(int&) or test(const int&) because in perfect_forwarder 'obj' is treated as
                      //  an int& or const int& (because it is named) so T in forward_with_deduction is deduced as int& 
                      //  or const int&. The T&& in static_cast<T&&>(obj) then collapses to int& or const int& - which is not what 
                      //  we want in the bottom two cases.
                      perfect_forwarder(x);           
                      perfect_forwarder(y);           
                      perfect_forwarder(std::move(x));
                      perfect_forwarder(std::move(y));
                  }
                  

                  這篇關于為什么使用 std::forward 禁用模板參數推導?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='K3QY8'></small><noframes id='K3QY8'>

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

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

                              <tbody id='K3QY8'></tbody>

                            <tfoot id='K3QY8'></tfoot>
                            主站蜘蛛池模板: 中文在线字幕观看 | 日韩精品大片 | 日韩欧美一区二区三区 | 久久久久国产精品夜夜夜夜夜 | 九九九久久久 | 国产精品自拍小视频 | 久久久久国产精品视频 | 亚洲二区视频 | 黄色免费片 | 欧美日韩一二三区 | 国产免费视频 | 一区二区三区四区精品 | 天堂影院av| 国产一区二区在线播放 | 久久国产精品99久久人人澡 | 91蜜桃在线观看 | 国产深夜福利 | 狠狠干狠狠插 | av一二三区 | 国产黄色av网站 | 91久| 国产成人精品一区二区三区视频 | 欧美一级黄色片 | 欧美色综合天天久久综合精品 | 国产又爽又黄免费视频 | 中文字幕在线观看免费 | 日韩伦理视频 | 亚洲二级片 | 欧美人与性动交α欧美精品 | 久草久草久草 | 国内av在线 | 黄色精品视频 | 国产激情一区二区三区 | 欧美精品日韩少妇 | 天天干天天操 | 亚洲欧美在线一区 | 亚洲免费小视频 | 天堂中文av | 中文字幕不卡在线观看 | 成人在线免费视频观看 | 性史性dvd影片农村毛片 |