{"id":321428,"date":"2021-04-14T15:00:23","date_gmt":"2021-04-14T15:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=321428"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=321428","title":{"rendered":"\u041f\u0435\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u0430\u0432\u0434\u0430 \u043e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0435 \u043a\u043e\u043f\u0438\u0439 \u0432 C++"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\"><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/551782\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/w5\/jh\/zc\/w5jhzczzrry6fwgqh5xmm5rx9qo.png\"><\/div>\n<p><\/a><\/p>\n<p>  \u041f\u0440\u043e\u043f\u0443\u0441\u043a \u043a\u043e\u043f\u0438\u0439 (copy elision) \u2013 \u044d\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043a\u0430\u043a \u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u0438\u043c\u0435\u043d\u0438, \u0443\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442 \u043b\u0438\u0448\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f. \u041e\u043d\u0430 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043a\u043e\u043f\u0438\u0439, \u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 C++, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u044f \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430\u044f \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u043e\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. <a name=\"habracut\"><\/a><\/p>\n<h2><font color=\"#3AC1EF\">\u0412\u0432\u043e\u0434 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u044b\u0432\u0430 \u0441\u0442\u0440\u043e\u043a\u0438<\/font><\/h2>\n<p>  \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">#include &lt;string&gt; #include &lt;string_view&gt;  \/\/ \u0422\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0440\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c struct Widget {   std::string s; };  void consume(Widget w);  Widget doSomeVeryComplicatedThingWithSeveralArguments(   int arg1, std::string_view arg2);  void someFunction() {     consume(doSomeVeryComplicatedThingWithSeveralArguments(123, &quot;hello&quot;)); }<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0430, \u0437\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u043e:<\/p>\n<pre><code class=\"bash\">someFunction():                      # @someFunction()         pushq   %rbx         subq    $32, %rsp         movq    %rsp, %rbx         movl    $5, %edx         movl    $.L.str, %ecx         movq    %rbx, %rdi         movl    $123, %esi         callq   doSomeVeryComplicatedThingWithSeveralArguments(int, std::basic_string_view&lt;char, std::char_traits&lt;char&gt; &gt;)         movq    %rbx, %rdi         callq   consume(Widget)         movq    (%rsp), %rdi         leaq    16(%rsp), %rax         cmpq    %rax, %rdi         je      .LBB0_2         callq   operator delete(void*) .LBB0_2:         addq    $32, %rsp         popq    %rbx         retq .L.str:         .asciz  &quot;hello&quot;<\/code><\/pre>\n<p>  \u0412\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 <code>Widget<\/code>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0438\u0437 <code>doSomeVeryComplicatedThingWithSeveralArguments<\/code>, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0441\u0442\u0435\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u0434 \u043d\u0435\u0433\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u043b\u0430 <code>someFunction<\/code>. \u0417\u0430\u0442\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u043b\u043e\u0441\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e <a href=\"https:\/\/wolchok.org\/posts\/parameter-passing\/\">\u043f\u0440\u0430\u0432\u0438\u043b\u0430\u0445 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 (\u0430\u043d\u0433\u043b.)<\/a>, \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u044d\u0442\u0443 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0441\u0442\u0435\u043a\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. <\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>someFuncton <\/code>\u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0432\u0430\u043c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u043e\u0439, \u0438\u043b\u0438 \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 <code>doSomeVeryComplicatedThingWithSeveralArguments <\/code>\u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u043c\u044f, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">void someFunctionV2() {     auto complicatedThingResult =         doSomeVeryComplicatedThingWithSeveralArguments(123, &quot;hello&quot;);     consume(complicatedThingResult); }<\/code><\/pre>\n<p>  \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, <a href=\"https:\/\/godbolt.org\/#g:!((g:!((g:!((h:codeEditor,i:(fontScale:14,fontUsePx:&#39;0&#39;,j:1,lang:c%2B%2B,selection:(endColumn:37,endLineNumber:22,positionColumn:37,positionLineNumber:22,selectionStartColumn:37,selectionStartLineNumber:22,startColumn:37,startLineNumber:22),source:&#39;%23include+%3Cstring%3E%0A%23include+%3Cstring_view%3E%0A%0A\/\/+Some+type+that+is+expensive+to+copy,+non-trivial+to+destroy,+and+cheap+but%0A\/\/+not+free+to+move.%0Astruct+Widget+%7B%0A++std::string+s%3B%0A%7D%3B%0A%0Avoid+consume(Widget+w)%3B%0A%0AWidget+doSomeVeryComplicatedThingWithSeveralArguments(%0A++int+arg1,+std::string_view+arg2)%3B%0A%0Avoid+someFunction()+%7B%0A++++consume(doSomeVeryComplicatedThingWithSeveralArguments(123,+%22hello%22))%3B%0A%7D%0A%0Avoid+someFunctionV2()+%7B%0A++++auto+complicatedThingResult+%3D%0A++++++++doSomeVeryComplicatedThingWithSeveralArguments(123,+%22hello%22)%3B%0A++++consume(complicatedThingResult)%3B%0A%7D&#39;),l:&#39;5&#39;,n:&#39;0&#39;,o:&#39;C%2B%2B+source+%231&#39;,t:&#39;0&#39;)),k:44.30067775723968,l:&#39;4&#39;,n:&#39;0&#39;,o:&#39;&#39;,s:0,t:&#39;0&#39;),(g:!((h:compiler,i:(compiler:clang1101,filters:(b:&#39;0&#39;,binary:&#39;1&#39;,commentOnly:&#39;0&#39;,demangle:&#39;0&#39;,directives:&#39;0&#39;,execute:&#39;1&#39;,intel:&#39;1&#39;,libraryCode:&#39;1&#39;,trim:&#39;1&#39;),fontScale:14,fontUsePx:&#39;0&#39;,j:1,lang:c%2B%2B,libs:!(),options:&#39;-O3+-std%3Dc%2B%2B20+-fno-exceptions&#39;,selection:(endColumn:26,endLineNumber:37,positionColumn:26,positionLineNumber:37,selectionStartColumn:27,selectionStartLineNumber:36,startColumn:27,startLineNumber:36),source:1),l:&#39;5&#39;,n:&#39;0&#39;,o:&#39;x86-64+clang+11.0.1+(Editor+%231,+Compiler+%231)+C%2B%2B&#39;,t:&#39;0&#39;)),k:55.69932224276032,l:&#39;4&#39;,n:&#39;0&#39;,o:&#39;&#39;,s:0,t:&#39;0&#39;)),l:&#39;2&#39;,n:&#39;0&#39;,o:&#39;&#39;,t:&#39;0&#39;)),version:4\">\u0432\u0441\u0435 \u0441\u044a\u0435\u0437\u0436\u0430\u0435\u0442<\/a>:<\/p>\n<pre><code class=\"bash\">someFunctionV2():                    # @someFunctionV2()         pushq   %r15         pushq   %r14         pushq   %r12         pushq   %rbx         subq    $72, %rsp         leaq    40(%rsp), %rdi         movl    $5, %edx         movl    $.L.str, %ecx         movl    $123, %esi         callq   doSomeVeryComplicatedThingWithSeveralArguments(int, std::basic_string_view&lt;char, std::char_traits&lt;char&gt; &gt;)         leaq    24(%rsp), %r12         movq    %r12, 8(%rsp)         movq    40(%rsp), %r14         movq    48(%rsp), %rbx         movq    %r12, %r15         cmpq    $16, %rbx         jb      .LBB1_4         testq   %rbx, %rbx         js      .LBB1_13         movq    %rbx, %rdi         incq    %rdi         js      .LBB1_14         callq   operator new(unsigned long)         movq    %rax, %r15         movq    %rax, 8(%rsp)         movq    %rbx, 24(%rsp) .LBB1_4:         testq   %rbx, %rbx         je      .LBB1_8         cmpq    $1, %rbx         jne     .LBB1_7         movb    (%r14), %al         movb    %al, (%r15)         jmp     .LBB1_8 .LBB1_7:         movq    %r15, %rdi         movq    %r14, %rsi         movq    %rbx, %rdx         callq   memcpy .LBB1_8:         movq    %rbx, 16(%rsp)         movb    $0, (%r15,%rbx)         leaq    8(%rsp), %rdi         callq   consume(Widget)         movq    8(%rsp), %rdi         cmpq    %r12, %rdi         je      .LBB1_10         callq   operator delete(void*) .LBB1_10:         movq    40(%rsp), %rdi         leaq    56(%rsp), %rax         cmpq    %rax, %rdi         je      .LBB1_12         callq   operator delete(void*) .LBB1_12:         addq    $72, %rsp         popq    %rbx         popq    %r12         popq    %r14         popq    %r15         retq .LBB1_13:         movl    $.L.str.2, %edi         callq   std::__throw_length_error(char const*) .LBB1_14:         callq   std::__throw_bad_alloc() .L.str:         .asciz  &quot;hello&quot;  .L.str.2:         .asciz  &quot;basic_string::_M_create&quot;<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0431\u0435\u0440\u0435\u043c \u043d\u0430\u0448 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 <code>Widget<\/code>, <code>complicatedThingResult<\/code>, \u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u043e\u0432\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 <code>Widget<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430. \u041f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0434\u0432\u0430 <code>Widget<\/code>: <code>complicatedThingResult<\/code> \u0438 \u0431\u0435\u0437\u044b\u043c\u044f\u043d\u043d\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 <code>Widget<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b\u0438 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0436\u0438\u0434\u0430\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 <code>someFunctionV2()<\/code>, \u0441\u0434\u0435\u043b\u0430\u0432 \u0435\u0435 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 <code>someFunction<\/code>, \u043d\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442.<\/p>\n<p>  \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0437\u0430\u0431\u044b\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c <code>std::move complicatedThingResult<\/code>:<\/p>\n<pre><code class=\"cpp\">void someFunctionV3() {     auto complicatedThingResult =         doSomeVeryComplicatedThingWithSeveralArguments(123, &quot;hello&quot;);     consume(std::move(complicatedThingResult)); }<\/code><\/pre>\n<p>  \u0418 \u0442\u0435\u043f\u0435\u0440\u044c <a href=\"https:\/\/godbolt.org\/#g:!((g:!((g:!((h:codeEditor,i:(fontScale:14,fontUsePx:&#39;0&#39;,j:1,lang:c%2B%2B,selection:(endColumn:2,endLineNumber:17,positionColumn:2,positionLineNumber:17,selectionStartColumn:2,selectionStartLineNumber:17,startColumn:2,startLineNumber:17),source:&#39;%23include+%3Cstring%3E%0A%23include+%3Cstring_view%3E%0A%0A\/\/+Some+type+that+is+expensive+to+copy,+non-trivial+to+destroy,+and+cheap+but%0A\/\/+not+free+to+move.%0Astruct+Widget+%7B%0A++std::string+s%3B%0A%7D%3B%0A%0Avoid+consume(Widget+w)%3B%0A%0AWidget+doSomeVeryComplicatedThingWithSeveralArguments(%0A++int+arg1,+std::string_view+arg2)%3B%0A%0Avoid+someFunction()+%7B%0A++++consume(doSomeVeryComplicatedThingWithSeveralArguments(123,+%22hello%22))%3B%0A%7D%0A%0Avoid+someFunctionV3()+%7B%0A++++auto+complicatedThingResult+%3D%0A++++++++doSomeVeryComplicatedThingWithSeveralArguments(123,+%22hello%22)%3B%0A++++consume(std::move(complicatedThingResult))%3B%0A%7D&#39;),l:&#39;5&#39;,n:&#39;0&#39;,o:&#39;C%2B%2B+source+%231&#39;,t:&#39;0&#39;)),k:44.30067775723968,l:&#39;4&#39;,n:&#39;0&#39;,o:&#39;&#39;,s:0,t:&#39;0&#39;),(g:!((h:compiler,i:(compiler:clang1101,filters:(b:&#39;0&#39;,binary:&#39;1&#39;,commentOnly:&#39;0&#39;,demangle:&#39;0&#39;,directives:&#39;0&#39;,execute:&#39;1&#39;,intel:&#39;1&#39;,libraryCode:&#39;1&#39;,trim:&#39;1&#39;),fontScale:14,fontUsePx:&#39;0&#39;,j:1,lang:c%2B%2B,libs:!(),options:&#39;-O3+-std%3Dc%2B%2B20+-fno-exceptions&#39;,selection:(endColumn:9,endLineNumber:55,positionColumn:9,positionLineNumber:55,selectionStartColumn:9,selectionStartLineNumber:55,startColumn:9,startLineNumber:55),source:1),l:&#39;5&#39;,n:&#39;0&#39;,o:&#39;x86-64+clang+11.0.1+(Editor+%231,+Compiler+%231)+C%2B%2B&#39;,t:&#39;0&#39;)),k:55.69932224276032,l:&#39;4&#39;,n:&#39;0&#39;,o:&#39;&#39;,s:0,t:&#39;0&#39;)),l:&#39;2&#39;,n:&#39;0&#39;,o:&#39;&#39;,t:&#39;0&#39;)),version:4\">\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0430<\/a> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438, \u043a\u0430\u043a \u043d\u0430\u0448 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440. \u041f\u043e\u0441\u0442\u043e\u0439\u0442\u0435-\u043a\u0430\u2026\u0447\u0442\u043e?<\/p>\n<pre><code class=\"bash\">someFunctionV3():                    # @someFunctionV3()         pushq   %r14         pushq   %rbx         subq    $72, %rsp         leaq    8(%rsp), %rdi         movl    $5, %edx         movl    $.L.str, %ecx         movl    $123, %esi         callq   doSomeVeryComplicatedThingWithSeveralArguments(int, std::basic_string_view&lt;char, std::char_traits&lt;char&gt; &gt;)         leaq    56(%rsp), %r14         movq    %r14, 40(%rsp)         movq    8(%rsp), %rax         leaq    24(%rsp), %rbx         cmpq    %rbx, %rax         je      .LBB1_1         movq    %rax, 40(%rsp)         movq    24(%rsp), %rax         movq    %rax, 56(%rsp)         jmp     .LBB1_3 .LBB1_1:         movups  (%rax), %xmm0         movups  %xmm0, (%r14) .LBB1_3:         movq    16(%rsp), %rax         movq    %rax, 48(%rsp)         movq    %rbx, 8(%rsp)         movq    $0, 16(%rsp)         movb    $0, 24(%rsp)         leaq    40(%rsp), %rdi         callq   consume(Widget)         movq    40(%rsp), %rdi         cmpq    %r14, %rdi         je      .LBB1_5         callq   operator delete(void*) .LBB1_5:         movq    8(%rsp), %rdi         cmpq    %rbx, %rdi         je      .LBB1_7         callq   operator delete(void*) .LBB1_7:         addq    $72, %rsp         popq    %rbx         popq    %r14         retq .L.str:         .asciz  &quot;hello&quot;<\/code><\/pre>\n<p>  \u0423 \u043d\u0430\u0441 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 <code>Widget<\/code>, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c. \u041f\u0435\u0440\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f <code>someFunction <\/code>\u0432\u0441\u0435 \u0435\u0449\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u043d\u044c\u0448\u0435 \u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435!<\/p>\n<h2><font color=\"#3AC1EF\">\u0427\u0442\u043e \u0436\u0435 \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442?<\/font><\/h2>\n<p>  \u0421\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u043f\u0438\u0439 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/copy_elision\">\u0441\u043f\u0438\u0441\u043a\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432<\/a>. (\u0413\u043e\u0432\u043e\u0440\u044f \u043a\u043e\u0440\u043e\u0442\u043a\u043e, \u043f\u0440\u0438 RVO<sup>1<\/sup> \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0437 <code>prvalue <\/code>\u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u0438 NRVO<sup>2<\/sup> \u0438 \u0432 \u0440\u044f\u0434\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438 \u043f\u0440\u043e\u043f\u0443\u0441\u043a \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u043c. \u0412\u0441\u0435.). \u041d\u0430 \u0442\u043e \u0435\u0441\u0442\u044c \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0441\u043a\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430: \u0432\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0433\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0451 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e. \u0418, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u0432\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0435, \u0447\u0442\u043e, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0421++, \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437 \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u041d\u043e \u0435\u0441\u043b\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0443\u0434\u0430\u043b\u044f\u044f \u043f\u0430\u0440\u044b \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043a\u043e\u043f\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e\/\u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0438 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0437\u0440\u0443\u0448\u0438\u0442\u044c \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<p>  \u0413\u043e\u0432\u043e\u0440\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e, \u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u043f\u0443\u0441\u043a \u043a\u043e\u043f\u0438\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439 \u043d\u0435\u0442 \u0442\u0430\u043a\u0438\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u043c \u043d\u0430\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c. \u0412 \u044d\u0442\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0442\u0430\u043a\u0438\u0435 \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u0430\u043a \u00ab\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u0434 \u0435\u0435 \u0432\u044b\u0445\u043e\u0434\u043e\u043c \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438\u00bb \u0438\u043b\u0438 \u00ab\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u043d\u0435\u0439 \u043d\u0435 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b\u043e\u0441\u044c, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0430\u00bb. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0442\u0430\u043a\u0438\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u0443\u0447\u0442\u0435\u043d\u044b, \u043d\u043e \u0432 C++20 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u043d\u043d\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u044d\u0442\u043e\u0433\u043e \u0442\u043e\u0447\u043d\u043e \u043d\u0435\u0442.<\/p>\n<p>  1. RVO (return value optimization) \u2014 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<br \/>  2. NRVO (named return value optimization) \u2014 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  <a href=\"http:\/\/ruvds.com\/ru-rub?utm_source=habr&amp;utm_medium=perevod&amp;utm_campaign=ru_vds&amp;utm_content=sadtrue#order\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ou\/g5\/kh\/oug5kh6sjydt9llengsiebnp40w.png\"><\/a><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/551782\/\"> https:\/\/habr.com\/ru\/company\/ruvds\/blog\/551782\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\"><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/551782\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/w5\/jh\/zc\/w5jhzczzrry6fwgqh5xmm5rx9qo.png\"><\/div>\n<p><\/a><\/p>\n<p>  \u041f\u0440\u043e\u043f\u0443\u0441\u043a \u043a\u043e\u043f\u0438\u0439 (copy elision) \u2013 \u044d\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043a\u0430\u043a \u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u0438\u043c\u0435\u043d\u0438, \u0443\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442 \u043b\u0438\u0448\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f. \u041e\u043d\u0430 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043a\u043e\u043f\u0438\u0439, \u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 C++, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u044f \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430\u044f \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0430\u044f \u043e\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-321428","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=321428"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321428\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}