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

      <small id='82F3m'></small><noframes id='82F3m'>

        <bdo id='82F3m'></bdo><ul id='82F3m'></ul>
    2. <legend id='82F3m'><style id='82F3m'><dir id='82F3m'><q id='82F3m'></q></dir></style></legend>

      1. RVO 是否适用于对象成员?

        时间:2023-10-06
      2. <tfoot id='afCo4'></tfoot>

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

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

                <tbody id='afCo4'></tbody>
                <bdo id='afCo4'></bdo><ul id='afCo4'></ul>

                  <i id='afCo4'><tr id='afCo4'><dt id='afCo4'><q id='afCo4'><span id='afCo4'><b id='afCo4'><form id='afCo4'><ins id='afCo4'></ins><ul id='afCo4'></ul><sub id='afCo4'></sub></form><legend id='afCo4'></legend><bdo id='afCo4'><pre id='afCo4'><center id='afCo4'></center></pre></bdo></b><th id='afCo4'></th></span></q></dt></tr></i><div id='afCo4'><tfoot id='afCo4'></tfoot><dl id='afCo4'><fieldset id='afCo4'></fieldset></dl></div>
                  本文介绍了RVO 是否适用于对象成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  考虑以下事项:

                  struct A { /* ... */ };
                  
                  A foo() {
                    auto p = std::make_pair(A{}, 2);
                    // ... do something
                    return p.first;
                  }
                  
                  auto a = foo();
                  

                  p.first 会被复制、移动或 RVO 编辑吗?

                  Will p.first be copied, moved or RVO-ed?

                  推荐答案

                  我发现在 Visual Studio 2010 和 gcc-5.1 RVO 中应用(参见例如 http://coliru.stacked-crooked.com/a/17666dd9e532da76).

                  I've found in Visual Studio 2010 and in gcc-5.1 RVO is not applied (see for example http://coliru.stacked-crooked.com/a/17666dd9e532da76).

                  标准的相关部分是12.8.31.1 [class.copy].它指出允许复制省略(我的突出显示):

                  The relevant section of the standard is 12.8.31.1 [class.copy]. It states that copy elision is permitted (my highlighting):

                  在具有类返回类型的函数中的return语句中,当表达式为非易失性自动对象的名称(除了函数参数或异常引入的变量-声明一个与函数返回类型具有相同类型(忽略cv限定)的处理程序([except.handle])),可以通过将自动对象直接构造到函数的返回值中来省略复制/移动操作

                  in a return statement in a function with a class return type, when the expression is the name of a non-volatile automatic object (other than a function parameter or a variable introduced by the exception-declaration of a handler ([except.handle])) with the same type (ignoring cv-qualification) as the function return type, the copy/move operation can be omitted by constructing the automatic object directly into the function's return value

                  由于 p.first 不是对象的名称,因此禁止 RVO.

                  Since p.first is not the name of an object, RVO is prohibited.

                  这篇关于RVO 是否适用于对象成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在代码中正确使用 %USERPROFILE%? 下一篇:C2070 - 操作数大小非法

                  相关文章

                  最新文章

                • <tfoot id='hWsP3'></tfoot>

                      <bdo id='hWsP3'></bdo><ul id='hWsP3'></ul>

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

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