久久久久久久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 禁用模板參數(shù)推導(dǎo)?

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

              <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 禁用模板參數(shù)推導(dǎo)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

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

                  在 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 似乎僅用于禁用模板參數(shù)推導(dǎo).在這種情況下故意禁用它有什么意義?

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

                  推薦答案

                  如果將 X 類型的對(duì)象的右值引用傳遞給采用 T&& 類型的模板函數(shù) 作為其參數(shù),模板參數(shù)推導(dǎo)推導(dǎo)出 TX.因此,參數(shù)的類型為 X&&.如果函數(shù)參數(shù)是左值或 const 左值,則編譯器將其類型推導(dǎo)為該類型的左值引用或 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 使用模板參數(shù)推導(dǎo):

                  If std::forward used template argument deduction:

                  由于帶有名稱的對(duì)象是左值,因此std::forward 唯一一次正確地轉(zhuǎn)換為T&&參數(shù)是一個(gè)未命名的右值(如 7func()).在完美轉(zhuǎn)發(fā)的情況下,您傳遞給 std::forwardarg 是一個(gè)左值,因?yàn)樗幸粋€(gè)名稱.std::forward 的類型將被推導(dǎo)出為左值引用或常量左值引用.引用折疊規(guī)則將導(dǎo)致 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));
                  }
                  

                  這篇關(guān)于為什么使用 std::forward 禁用模板參數(shù)推導(dǎo)?的文章就介紹到這了,希望我們推薦的答案對(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)庫)
                  gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數(shù)模板,而 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在线播放网 | 激情五月婷婷综合 | 亚洲人a| 免费观看视频www | 一区二区三区高清不卡 | 国产性生活一级片 | 日韩视频在线免费观看 | 噜久寡妇噜噜久久寡妇 | 亚洲女人天堂成人av在线 | 日本一区二区电影 | 日韩成人影院在线观看 | 国产一区二区中文字幕 | 国产91精品网站 | 欧美在线一区二区三区 | 成人三级视频在线观看 | 久久最新精品 | 欧美日韩国产一区 | 亚洲精品1区 | 玖玖玖在线观看 | 亚洲欧洲视频 | 国产成人精品免费视频大全最热 | 91精品国产综合久久久久 | 超碰97免费在线 | 精品日韩一区 | 国产亚洲精品精品国产亚洲综合 | 国产xxxx在线| 国产精品久久久久久妇女 | 日韩精品一区二区三区中文字幕 | 日韩中文在线视频 | 欧美性网站| 欧美成人免费在线 | 欧美久久久久久久久 | 国产精品爱久久久久久久 | 黄一区二区三区 | 欧美国产亚洲一区二区 | 日日操夜夜操视频 | 狠狠干天天干 | 国产人成精品一区二区三 | 6080yy精品一区二区三区 | 亚洲国产精品网站 |