{"id":403270,"date":"2024-06-29T17:01:40","date_gmt":"2024-06-29T17:01:40","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=403270"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=403270","title":{"rendered":"<span>\u041e \u0440\u0430\u0437\u043d\u0438\u0446\u0435 \u043c\u0435\u0436\u0434\u0443 \u043b\u044f\u043c\u0431\u0434\u0430\u043c\u0438 \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0438 \u043e \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043b\u044f\u043c\u0431\u0434 \u0432 \u043d\u0435\u043a\u0442\u043e\u0440\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0426\u0435\u043b\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 &#8212; \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: \u0447\u0435\u043c \u043e\u043d\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0438\u0437\u0443\u0447\u0438\u0442\u044c, \u043a\u0430\u043a \u043e\u043d\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u0421++, Python 3 \u0438 Java.<\/p>\n<p>\u041d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"http:\/\/godbolt.org\/\" rel=\"noopener noreferrer nofollow\"><u>godbolt.org<\/u><\/a><u>,<\/u> \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0438 \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438\u043b\u0438 \u0431\u0430\u0439\u0442 \u043a\u043e\u0434. \u042f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0435 \u043d\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u0430 \u043d\u0430 \u044d\u0442\u043e\u043c \u0441\u0430\u0439\u0442\u0435. <\/p>\n<h3>C++<\/h3>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f? \u041c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#8212; \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u044f\u0437\u044b\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0421++, \u043f\u0435\u0440\u0435\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 \u0435\u0451 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u0438\u043f\u043e\u0432 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0435 \u043e\u0434\u043d\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0434\u0440\u0443\u0433\u0443\u044e, \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u043c \u0444\u0430\u0439\u043b\u0435. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0436\u0435 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0451\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u043a\u043e\u0439 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u0430\u043a\u0430\u044f, \u0447\u0442\u043e \u044d\u0442\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 calling conventions. <\/p>\n<p>\u041e\u043a\u0440\u043e\u043c\u044f \u043e\u0431\u044b\u043a\u043d\u043e\u0432\u0435\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432 \u0421++ \u0435\u0441\u0442\u044c \u0438 \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u041a\u0430\u043a \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u043e, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 &#171;\u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c&#187; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0442\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b, \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0438\u043b\u0438 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 (\u0438\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0438\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043d\u0438\u0445). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441 \u043b\u044f\u043c\u0431\u0434\u0430\u043c\u0438 \u043d\u0430 \u0421++ \u0438 \u043d\u0430 \u0442\u043e, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f. \u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c gcc 12.2 \u0441 \u0444\u043b\u0430\u0433\u043e\u043c <code>-Os<\/code> (\u0447\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0442\u0435\u043c \u043f\u0440\u043e\u0449\u0435 \u0435\u0433\u043e \u0447\u0438\u0442\u0430\u0442\u044c). <\/p>\n<pre><code class=\"cpp\">#include &lt;vector> #include &lt;cstdio>  \/\/ extern so that it won`t be inlined \/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u043a\u0430\u043a extern, \u0447\u0442\u043e\u0431\u044b \u0435\u0451 \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e \u0437\u0430\u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c extern void for_each(const std::vector&lt;int>&amp; vec, void (*func) (int));  void example(const std::vector&lt;int>&amp; vec) {     for_each(vec, [] (int n) {         printf(\"%d\\n\", n);     }); }<\/code><\/pre>\n<pre><code class=\"assembly\">.LC0:         .string \"%d\\n\" example(std::vector&lt;int, std::allocator&lt;int> > const&amp;)::{lambda(int)#1}::_FUN(int):         movl    %edi, %esi         xorl    %eax, %eax         movl    $.LC0, %edi         jmp     printf example(std::vector&lt;int, std::allocator&lt;int> > const&amp;):         movl    $example(std::vector&lt;int, std::allocator&lt;int> > const&amp;)::{lambda(int)#1}::_FUN(int), %esi         jmp     for_each(std::vector&lt;int, std::allocator&lt;int> > const&amp;, void (*)(int)) \/\/ note that using jmp instead of call is an optimization; the called  \/\/ function will return to the callee of the current function, skipping `example`<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0435 \u0432\u0438\u0434\u0438\u043c: \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u0431\u044b\u043b\u0430 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (\u0442\u043e \u0435\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u043c\u044b \u0431\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0442\u0430\u043a\u043e\u0433\u043e \u0436\u0435 \u0442\u0438\u043f\u0430 \u0438 \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u0442\u0435\u043b\u043e\u043c, \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440 \u0431\u044b\u043b \u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u0436\u0435). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0433\u0434\u0435 \u043b\u044f\u043c\u0431\u0434\u0430 \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u043d\u0430\u0440\u0443\u0436\u0438. <\/p>\n<pre><code class=\"cpp\">#include &lt;vector> #include &lt;cstdio>  extern void for_each(const std::vector&lt;int>&amp; vec, void (*func) (int));  void example(const std::vector&lt;int>&amp; vec, int threshold) {     for_each(vec, [threshold] (int n) {         if (n > threshold) {             printf(\"%d\\n\", n);         }     }); }<\/code><\/pre>\n<p>\u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u044d\u0442\u043e \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"cpp\">&lt;source>: In function 'void example(const std::vector&lt;int>&amp;, int)': &lt;source>:7:19: error: cannot convert 'example(const std::vector&lt;int>&amp;, int)::&lt;lambda(int)>' to 'void (*)(int)'     7 |     for_each(vec, [threshold] (int n) {       |                   ^~~~~~~~~~~~~~~~~~~~~       |                   |       |                   example(const std::vector&lt;int>&amp;, int)::&lt;lambda(int)>     8 |         if (n > threshold) {       |         ~~~~~~~~~~~~~~~~~~~~     9 |             printf(\"%d\\n\", n);       |             ~~~~~~~~~~~~~~~~~~    10 |         }       |         ~              11 |     });       |     ~               &lt;source>:4:58: note:   initializing argument 2 of 'void for_each(const std::vector&lt;int>&amp;, void (*)(int))'     4 | extern void for_each(const std::vector&lt;int>&amp; vec, void (*func) (int));       |                                                   ~~~~~~~^~~~~~~~~~~ Compiler returned: 1<\/code><\/pre>\n<p>\u0412\u044b\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u043d\u0430\u0440\u0443\u0436\u0438, \u0438\u043c\u0435\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0442\u0438\u043f, \u0447\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0435, <code>example(const std::vector&lt;int>&amp;, int)::&lt;lambda(int)><\/code>, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0438\u043f \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u0433\u0434\u0435 \u043e\u043d\u0430 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430. <\/p>\n<p>\u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0436\u043d\u044b\u0445 \u0432\u044b\u0432\u043e\u0434\u0430. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u0430\u044f \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e (\u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432\u044b\u0448\u0435), \u044d\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0418 \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0441\u043d\u0430\u0440\u0443\u0436\u0438, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0442\u0438\u043f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c (\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#8212; \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0430). \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u043e\u0432\u043e\u0439 \u043b\u044f\u043c\u0431\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">#include &lt;vector> #include &lt;cstdio>  template &lt;typename Callable> void __attribute__ ((noinline)) for_each(const std::vector&lt;int>&amp; vec, Callable func) {     for (const auto&amp; elem : vec) {         func(elem);     } }  void example(const std::vector&lt;int>&amp; vec, int threshold) {     for_each(vec, [threshold] (int n) {         if (n > threshold) {             printf(\"%d\\n\", n);         }     }); }<\/code><\/pre>\n<pre><code class=\"assembly\">.LC0:         .string \"%d\\n\" void for_each&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}):         pushq   %r12         pushq   %rbp         movl    %esi, %ebp         pushq   %rbx         movq    8(%rdi), %r12         movq    (%rdi), %rbx .L2:         cmpq    %rbx, %r12         je      .L7         movl    (%rbx), %esi         cmpl    %ebp, %esi         jle     .L3         movl    $.LC0, %edi         xorl    %eax, %eax         call    printf .L3:         addq    $4, %rbx         jmp     .L2 .L7:         popq    %rbx         popq    %rbp         popq    %r12         ret example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int):         jmp     void for_each&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1})<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>for_each<\/code> \u0431\u044b\u043b\u0430 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u0438 \u043d\u0430\u0448\u0430 \u043b\u044f\u043c\u0431\u0434\u0430 \u0442\u0443\u0434\u0430 \u0437\u0430\u0438\u043d\u043b\u0430\u0439\u043d\u0438\u043b\u0430\u0441\u044c &#8212; \u0430 <code>for_each<\/code> \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0438 \u0447\u0438\u0441\u043b\u043e. <\/p>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u0421++ \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0438 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u0441\u044f \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<p>\u041d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430! \u041c\u044b (\u0432\u0440\u043e\u0434\u0435) \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c \u043b\u044f\u043c\u0431\u0434\u044b, \u043d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0434\u043e\u0440\u043e\u0433\u0438\u043c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u044f <code>-Os<\/code>, \u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c \u0435\u0451 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043b\u044f\u043c\u0431\u0434\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<pre><code class=\"cpp\">#include &lt;vector> #include &lt;cstdio>  template &lt;typename Callable> void __attribute__ ((noinline)) for_each(const std::vector&lt;int>&amp; vec, Callable func) {     for (const auto&amp; elem : vec) {         func(elem);     } }  template &lt;typename Callable> void __attribute__ ((noinline)) for_each2(const std::vector&lt;int>&amp; vec, Callable func) {     for (auto iter = vec.rbegin(); iter != vec.rend(); iter++) {         func(*iter);     } }  void example(const std::vector&lt;int>&amp; vec, int threshold) {     auto lambda = [threshold] (int n) {         if (n > threshold) {             printf(\"%d\\n\", n);             printf(\"number: %d\", n);             printf(\"previous number: %d\", --n);             printf(\"next number: %d\", n + 2);         }     };     for_each(vec, lambda);     for_each2(vec, lambda); }<\/code><\/pre>\n<pre><code class=\"assembly\">.LC0:         .string \"%d\\n\" .LC1:         .string \"number: %d\" .LC2:         .string \"previous number: %d\" .LC3:         .string \"next number: %d\" example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}::operator()(int) const [clone .part.0]:         pushq   %rbx         movl    %edi, %esi         movl    %edi, %ebx         xorl    %eax, %eax         movl    $.LC0, %edi         call    printf         movl    %ebx, %esi         movl    $.LC1, %edi         xorl    %eax, %eax         call    printf         leal    -1(%rbx), %esi         movl    $.LC2, %edi         xorl    %eax, %eax         call    printf         leal    1(%rbx), %esi         movl    $.LC3, %edi         xorl    %eax, %eax         popq    %rbx         jmp     printf void for_each&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}):         pushq   %r12         pushq   %rbp         movl    %esi, %ebp         pushq   %rbx         movq    8(%rdi), %r12         movq    (%rdi), %rbx .L4:         cmpq    %rbx, %r12         je      .L9         movl    (%rbx), %edi         cmpl    %ebp, %edi         jle     .L5         call    example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}::operator()(int) const [clone .part.0] .L5:         addq    $4, %rbx         jmp     .L4 .L9:         popq    %rbx         popq    %rbp         popq    %r12         ret void for_each2&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}):         pushq   %r12         movl    %esi, %r12d         pushq   %rbp         movq    %rdi, %rbp         pushq   %rbx         movq    8(%rdi), %rbx .L11:         cmpq    %rbx, 0(%rbp)         je      .L15         movl    -4(%rbx), %edi         cmpl    %r12d, %edi         jle     .L12         call    example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}::operator()(int) const [clone .part.0] .L12:         subq    $4, %rbx         jmp     .L11 .L15:         popq    %rbx         popq    %rbp         popq    %r12         ret example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int):         subq    $24, %rsp         movl    %esi, 12(%rsp)         movq    %rdi, (%rsp)         call    void for_each&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1})         movl    12(%rsp), %esi         movq    (%rsp), %rdi         addq    $24, %rsp         jmp     void for_each2&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1})<\/code><\/pre>\n<p>\u041b\u044f\u043c\u0431\u0434\u0430 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0447\u0438\u0441\u043b\u043e \u0438 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437. \u0421\u0430\u043c\u0430 \u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 <code>n > threshold<\/code> \u0437\u0430\u0438\u043d\u043b\u0430\u0439\u043d\u0438\u043b\u0430\u0441\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>for_each<\/code> \u0438 <code>for_each2<\/code>! \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0430 <code>operator()(int) const<\/code> \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0430\u043c\u0435\u043a\u0430\u0435\u0442 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u0430\u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0440\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043b\u044f\u043c\u0431\u0434\u0430 \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u043b\u0430 \u0438 \u0438\u043c\u0435\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 () [\u043a\u0440\u0443\u0433\u043b\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438]. \u0415\u0449\u0451 \u043d\u0435\u043c\u043d\u043e\u0433\u043e, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0442 \u043b\u044f\u043c\u0431\u0434\u044b \u043d\u0435 \u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c:<\/p>\n<pre><code class=\"cpp\">#include &lt;vector> #include &lt;cstdio>  extern bool predicate(int a, int threshold);  template &lt;typename Callable> void __attribute__ ((noinline)) for_each(const std::vector&lt;int>&amp; vec, Callable func) {     for (const auto&amp; elem : vec) {         func(elem);     } }  template &lt;typename Callable> void __attribute__ ((noinline)) for_each2(const std::vector&lt;int>&amp; vec, Callable func) {     for (auto iter = vec.rbegin(); iter != vec.rend(); iter++) {         func(*iter);     } }  void example(const std::vector&lt;int>&amp; vec, int threshold) {     auto lambda = [threshold] (int n) {         if (predicate(n, threshold)) {             printf(\"%d\\n\", n);             printf(\"number: %d\", n);             printf(\"previous number: %d\", --n);             printf(\"next number: %d\", n + 2);         }     };     for_each(vec, lambda);     for_each2(vec, lambda); }<\/code><\/pre>\n<pre><code class=\"assembly\">.LC0:         .string \"%d\\n\" .LC1:         .string \"number: %d\" .LC2:         .string \"previous number: %d\" .LC3:         .string \"next number: %d\" \/\/ first argument in always passed in %edi, second in %esi, third in %edx example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}::operator()(int) const [clone .isra.0]:         pushq   %rbx         movl    %esi, %ebx         movl    %edi, %esi         movl    %ebx, %edi         call    predicate(int, int)         testb   %al, %al         je      .L1         movl    %ebx, %esi         movl    $.LC0, %edi         xorl    %eax, %eax         call    printf         movl    %ebx, %esi         movl    $.LC1, %edi         xorl    %eax, %eax         call    printf         leal    -1(%rbx), %esi         movl    $.LC2, %edi         xorl    %eax, %eax         call    printf         leal    1(%rbx), %esi         movl    $.LC3, %edi         xorl    %eax, %eax         popq    %rbx         jmp     printf .L1:         popq    %rbx         ret void for_each2&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}):         pushq   %r12         movl    %esi, %r12d         pushq   %rbp         movq    %rdi, %rbp         pushq   %rbx         movq    8(%rdi), %rbx .L6:         cmpq    %rbx, 0(%rbp)         je      .L9         movl    -4(%rbx), %esi         movl    %r12d, %edi         subq    $4, %rbx         call    example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}::operator()(int) const [clone .isra.0]         jmp     .L6 .L9:         popq    %rbx         popq    %rbp         popq    %r12         ret void for_each&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}):         pushq   %r12         pushq   %rbp         movl    %esi, %ebp         pushq   %rbx         movq    8(%rdi), %r12         movq    (%rdi), %rbx .L11:         cmpq    %rbx, %r12         je      .L14         movl    (%rbx), %esi         movl    %ebp, %edi         addq    $4, %rbx         call    example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}::operator()(int) const [clone .isra.0]         jmp     .L11 .L14:         popq    %rbx         popq    %rbp         popq    %r12         ret example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int):         subq    $24, %rsp         movl    %esi, 12(%rsp)         movq    %rdi, (%rsp)         call    void for_each&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1})         movl    12(%rsp), %esi         movq    (%rsp), %rdi         addq    $24, %rsp         jmp     void for_each2&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1})<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u043a\u0440\u0443\u0433\u043b\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438, \u0438 \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c (\u043a\u0430\u043a \u0431\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0439 \u0432\u043e\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b) <code>threshold<\/code>, \u0430 \u0432\u0442\u043e\u0440\u044b\u043c &#8212; \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e &#8212; \u0447\u0438\u0441\u043b\u043e \u0438\u0437 \u0432\u0435\u043a\u0442\u043e\u0440\u0430. \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043c\u0435\u0441\u0442\u0430\u043c\u0438 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 <code>predicate<\/code>. \u0414\u0430\u043b\u044c\u0448\u0435 \u0432\u0441\u0451 \u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u0424\u0443\u043d\u043a\u0446\u0438\u0438 <code>for_each<\/code>, \u043a\u0430\u043a \u0438 \u043f\u0440\u0435\u0436\u0434\u0435, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u0438 <code>threshold<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043b\u044f\u043c\u0431\u0434\u0443. <\/p>\n<p>\u041d\u0430\u043f\u0441\u043b\u0435\u0434\u043e\u043a, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0445\u0438\u0442\u0440\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">#include &lt;vector> #include &lt;cstdio>  template &lt;typename Callable> void __attribute__ ((noinline)) for_each(const std::vector&lt;int>&amp; vec, Callable func) {     for (const auto&amp; elem : vec) {         func(elem);     } }  auto get_filtering_lambda(int threshold) {     return [threshold] (int n) {         if (n > threshold) {             printf(\"%d\\n\", n);         }     }; }   void example(const std::vector&lt;int>&amp; vec, int threshold) {     for_each(vec, get_filtering_lambda(threshold)); }<\/code><\/pre>\n<p>\u041a\u0430\u043a\u043e\u0439 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440 \u043c\u044b \u0431\u044b \u0437\u0434\u0435\u0441\u044c \u043e\u0436\u0438\u0434\u0430\u043b\u0438 \u0443\u0432\u0438\u0434\u0435\u0442\u044c? \u041a\u0430\u043a \u043c\u044b \u043f\u043e\u043c\u043d\u0438\u043c, <code>for_each<\/code> \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043b\u044f\u043c\u0431\u0434\u0430 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e <code>get_filtering_lambda<\/code> \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0438 \u0441\u0430\u043c\u044b\u0435 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"assembly\">.LC0:         .string \"%d\\n\" void for_each&lt;get_filtering_lambda(int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, get_filtering_lambda(int)::{lambda(int)#1}):         pushq   %r12         pushq   %rbp         movl    %esi, %ebp         pushq   %rbx         movq    8(%rdi), %r12         movq    (%rdi), %rbx .L2:         cmpq    %rbx, %r12         je      .L7         movl    (%rbx), %esi         cmpl    %ebp, %esi         jle     .L3         movl    $.LC0, %edi         xorl    %eax, %eax         call    printf .L3:         addq    $4, %rbx         jmp     .L2 .L7:         popq    %rbx         popq    %rbp         popq    %r12         ret get_filtering_lambda(int):         movl    %edi, %eax         ret example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int):         jmp     void for_each&lt;get_filtering_lambda(int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, get_filtering_lambda(int)::{lambda(int)#1})<\/code><\/pre>\n<p>\u041d\u0430\u0434\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043e\u043f\u0438\u0440\u0430\u044e\u0449\u0430\u044f\u0441\u044f \u043d\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u044b &#8212; \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430\u044f. \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043c\u043e\u0433 \u0431\u044b \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0443\u044e \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043a\u0430\u043a \u043c\u044b \u044d\u0442\u043e \u0443\u0436\u0435 \u0432\u0438\u0434\u0435\u043b\u0438 \u0432\u044b\u0448\u0435, \u043a\u043e\u0433\u0434\u0430 \u043b\u044f\u043c\u0431\u0434\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0430\u0441\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u043a\u0440\u0443\u0433\u043b\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b). \u041f\u043e\u0442\u043e\u043c \u044d\u0442\u0443 \u043b\u044f\u043c\u0431\u0434\u0443 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0430\u043a\u043e\u0432\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0435\u0432\u0430\u043c\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0443\u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043d\u0435\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e (\u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430). <\/p>\n<pre><code class=\"cpp\">class IIntConsumer { public:     virtual ~IIntConsumer() = 0;     virtual void consume(int) = 0;  }; void for_reach(const vector&lt;int>&amp; vec, IIntConsumer* func) {     for (const auto&amp; elem : vec) {         func->consume(elem);     } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0439 \u0432 \u0442\u0430\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 <code>IIntConsumer<\/code>, \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>for_each<\/code>. <\/p>\n<pre><code class=\"cpp\">void lambda_translation(int a, int captured0) {     if (a > captured0) {         printf(\"%d\", a);     } } class LambdaHolder: public IIntConsumer { public:     LambdaHolder(int a, int b, int captured0) : captured0(captured0) {}     void consume(int a) override {         lambda_translation(a, captured0);     }  private:     int captured0; };<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0431\u044b\u043b\u043e \u0431\u044b \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>for_each<\/code> \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0430\u044f \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u0431\u044a\u0451\u043c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 (\u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0440\u0438\u0441\u043a iTLB \u043f\u0440\u043e\u043c\u0430\u0445\u043e\u0432) \u0438 \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0435\u0438\u043b\u044f\u0446\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u044b\u0437\u043e\u0432 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043e\u0440\u043e\u0436\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 &#8212; \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c\u0441\u044f, \u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0445\u0443\u0436\u0435. <\/p>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0412 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438 \u0432 \u044f\u0437\u044b\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0435\u0442 \u043d\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u043d\u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0421++ &#8212; \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0433\u0438\u0431\u043a\u0438\u0439 \u044f\u0437\u044b\u043a, \u0438 \u0432 \u043d\u0451\u043c \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u043b\u0438 \u043b\u044f\u043c\u0431\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043d\u0435\u043a\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0442\u0438\u043f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c\u044b\u0445 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0430 \u043d\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043e\u043d\u0430 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442, \u0433\u0434\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e, \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>std::function&lt;RType(InTypes...)><\/code>. \u0418\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">void for_each(const vector&lt;int> &amp;vec, function&lt;void(int)> func) {     for (const auto &amp;elem: vec) {         func(elem);     } }   int main() {     int threshold = 1;     auto func = function&lt;void(int)>(             [threshold](int n) {                 if (n > threshold) {                     printf(\"%d\\n\", n);                 }             }     );     vector&lt;int> vec = {1, 2, 3};     for_each(vec, func); }<\/code><\/pre>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u0432 \u0421++ \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043d\u0435\u043a\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043d\u0435\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043a\u043e\u0434 <code>function<\/code> \u0432 STL \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 <s>\u0442\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0435\u0433\u043e \u0434\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0430 \u043f\u043e\u0442\u043e\u043c \u043e\u0431\u0444\u0443\u0441\u0446\u0438\u0440\u043e\u0432\u0430\u043b\u0438<\/s> (\u0434\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0448\u0443\u0442\u043a\u0430) \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"cpp\">template&lt;typename RType, typename... Args> class IFuncHolder { public:     virtual RType operator()(Args ...args) = 0;      virtual ~IFuncHolder() = default; };  template&lt;typename RType, typename Callable, typename... Args> class FuncHolderImpl : public IFuncHolder&lt;RType, Args...> { public:     FuncHolderImpl(Callable&amp;&amp; callable) : callable(callable) {}      ~FuncHolderImpl() {     }      RType operator()(Args ...args) override {         return callable(args...);     }  private:     Callable callable; };  template&lt;typename Signature> class my_function;  template&lt;typename RType, typename... Args> class my_function&lt;RType(Args...)> { public:     template&lt;typename Callable>     my_function(Callable&amp;&amp; f) {         func = new FuncHolderImpl&lt;RType, Callable, Args...>(std::forward&lt;Callable>(f));     }      ~my_function() {         delete func;     }      RType operator()(Args ...args) {         return func->operator()(args...);     }  private:     IFuncHolder&lt;RType, Args...> *func;  };  void for_each(const vector&lt;int> &amp;vec, my_function&lt;void(int)> func) {     for (const auto &amp;elem: vec) {         func(elem);     } }<\/code><\/pre>\n<h2>Python<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043a\u043e\u0434 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434 \u043e\u043d \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Python 3.7. \u0412\u043e\u043e\u0431\u0449\u0435-\u0442\u043e, \u0432 \u041f\u0438\u0442\u043e\u043d\u0435 \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 &#8212; \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043e\u0434\u043d\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u044d\u043a\u0441\u043f\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u0430. \u041d\u043e \u0432 \u041f\u0438\u0442\u043e\u043d\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0440\u0443\u0433\u043e\u0439, \u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u043d\u0430\u0440\u0443\u0436\u0438, \u043a\u0430\u043a \u0438 \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u0421++. <\/p>\n<p>\u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0447\u0438\u0442\u0430\u0442\u044c \u0431\u0430\u0439\u0442 \u043a\u043e\u0434 \u041f\u0438\u0442\u043e\u043d\u0430, \u043d\u0430\u0434\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0442\u0440\u0438 \u0432\u0435\u0449\u0438. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0447\u0438\u0441\u043b\u0430 \u0432 \u043b\u0435\u0432\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u043d\u043e\u043c\u0435\u0440\u0430 \u0441\u0442\u0440\u043e\u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 (\u043d\u0443\u043c\u0435\u0440\u0443\u044e\u0442\u0441\u044f \u0441 1), \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u0430 &#8212; \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0431\u0430\u0439\u0442-\u043a\u043e\u0434 \u041f\u0438\u0442\u043e\u043d\u0430 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443, \u0447\u0435\u043c \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u0438\u0437 \u0421, \u0421++ \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0430\u0434\u0440\u0435\u0441, \u043e\u0442\u043a\u0443\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 &#8212; \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u0442\u043a\u0430 (\u0444\u0443\u043d\u043a\u0446\u0438\u044f) <code>_start<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u0432 libstdc, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0436\u0435 \u0434\u0430\u043b\u044c\u0448\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>main<\/code> \u0438\u0437 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u0412 \u041f\u0438\u0442\u043e\u043d\u0435 \u0436\u0435 \u0431\u0430\u0439\u0442 \u043a\u043e\u0434 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0441 \u043f\u0435\u0440\u0432\u043e\u0439 \u0436\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 &#8212; \u043e\u043d \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0438, \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0442\u043e\u0440\u0430\u044f \u0438 \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 (\u043d\u0435 \u0434\u0440\u0443\u0433 \u0437\u0430 \u0434\u0440\u0443\u0433\u043e\u043c) \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u043c \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u0435. \u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u0431\u0430\u0439\u0442-\u043a\u043e\u0434 \u041f\u0438\u0442\u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0435\u043a\u043e\u0432\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u043e\u0439, \u0430 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 &#8212; \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0435 \u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u043c\u0438. <\/p>\n<pre><code class=\"python\">def func_generator(a):     def inner(b):         return a &lt; b      return inner  print(func_generator(2)(3))<\/code><\/pre>\n<pre><code class=\"assembly\"> 1            0 LOAD_CONST               0 (&lt;code object func_generator at 0x55ccef231910, file \"example.py\", line 1>)               2 LOAD_CONST               1 ('func_generator')               4 MAKE_FUNCTION            0               6 STORE_NAME               0 (func_generator)    7           8 LOAD_NAME                1 (print)              10 LOAD_NAME                0 (func_generator)              12 LOAD_CONST               2 (2)              14 CALL_FUNCTION            1              16 LOAD_CONST               3 (3)              18 CALL_FUNCTION            1              20 CALL_FUNCTION            1              22 POP_TOP              24 LOAD_CONST               4 (None)              26 RETURN_VALUE  Disassembly of &lt;code object func_generator at 0x55ccef231910, file \"example.py\", line 1>:   2           0 LOAD_CLOSURE             0 (a)               2 BUILD_TUPLE              1               4 LOAD_CONST               1 (&lt;code object inner at 0x55ccef204fc0, file \"example.py\", line 2>)               6 LOAD_CONST               2 ('func_generator.&lt;locals>.inner')               8 MAKE_FUNCTION            8              10 STORE_FAST               1 (inner)    5          12 LOAD_FAST                1 (inner)              14 RETURN_VALUE  Disassembly of &lt;code object inner at 0x55ccef204fc0, file \"example.py\", line 2>:   3           0 LOAD_DEREF               0 (a)               2 LOAD_FAST                0 (b)               4 COMPARE_OP               0 (&lt;)               6 RETURN_VALUE<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0436\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435? \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043a\u043e\u0434\u0430 \u043d\u0430 \u041f\u0438\u0442\u043e\u043d\u0435: \u043e\u043d\u0430 \u043a\u043b\u0430\u0434\u0451\u0442 \u043d\u0430 \u0441\u0442\u0435\u043a \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0417\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <code>MAKE_FUNCTION<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0438\u0442\u0430\u0442\u043e\u0440\u0430 \u041f\u0438\u0442\u043e\u043d\u0430. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043d\u043e\u0432\u043e\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e. <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0435\u0434\u044c\u043c\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0437 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u041e\u043d\u0430 \u043a\u043b\u0430\u0434\u0451\u0442 \u043d\u0430 \u0441\u0442\u0435\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 print \u0438 func_generator, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0435\u0451, \u0437\u0430\u0442\u0435\u043c \u043a\u043b\u0430\u0434\u0451\u0442 \u043d\u0430 \u0441\u0442\u0435\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0435\u0451, \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>print<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>None<\/code>, \u0447\u0442\u043e\u0431\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f. <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <code>func_generator<\/code>, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u0442\u043e\u0440\u0430\u044f \u043b\u0438\u043d\u0438\u044f \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430: \u043d\u0430 \u0441\u0442\u0435\u043a \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>a<\/code> (\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>LOAD_CLOSURE<\/code> \u0438 <code>LOAD_FAST<\/code> &#8212; \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435), \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043a\u043e\u0440\u0442\u0435\u0436 \u0438\u0437 \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043f\u043e\u0442\u043e\u043c \u043a\u043b\u0430\u0434\u0451\u0442 \u043d\u0430 \u0441\u0442\u0435\u043a \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043a\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 inner \u0438 \u0438\u043c\u044f \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0417\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <code>MAKE_FUNCTION<\/code> &#8212; \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a, \u0431\u0443\u0434\u0442\u043e \u0435\u0439 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043a\u043e\u0440\u0442\u0435\u0436 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0434\u0435\u043b\u0430\u0435\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/60b\/a0b\/d32\/60ba0bd32d757669fe96c1951c51c25d.png\" width=\"875\" height=\"326\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/60b\/a0b\/d32\/60ba0bd32d757669fe96c1951c51c25d.png\"\/><\/figure>\n<details class=\"spoiler\">\n<summary>\u0433\u0440\u0443\u0431\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434<\/summary>\n<div class=\"spoiler__content\">\n<p><code>MAKE_FUNCTION<\/code>(\u0444\u043b\u0430\u0433\u0438)<\/p>\n<p>\u041a\u043b\u0430\u0434\u0451\u0442 \u043d\u0430 \u0441\u0442\u0435\u043a \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0421\u043d\u0438\u0437\u0443 \u0432\u0432\u0435\u0440\u0445 \u0441\u0442\u0435\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0431\u0438\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>0x1: \u043a\u043e\u0440\u0442\u0435\u0436 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u0440\u043e\u043c\u0435 \u0442\u0435\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043a\u043b\u044e\u0447\u0443<\/p>\n<\/li>\n<li>\n<p>0x2: \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e \u043a\u043b\u044e\u0447\u0443<\/p>\n<\/li>\n<li>\n<p>0x4: \u043a\u043e\u0440\u0442\u0435\u0436 \u0441\u0442\u0440\u043e\u043a, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>0x8: \u043a\u043e\u0440\u0442\u0435\u0436, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0435\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u044f\u043c\u0431\u0434\u0430 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442. <\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0438\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f inner: \u043e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043d\u0430 \u0441\u0442\u0435\u043a, \u0437\u0430\u0442\u0435\u043c \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438) \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0438\u0445. <\/p>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043c\u044b \u0443\u0432\u0438\u0434\u0435\u043b\u0438, \u0447\u0442\u043e:<\/p>\n<ol>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u041f\u0438\u0442\u043e\u043d\u0435 (\u0432\u0441\u0435, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u044f\u043c\u0431\u0434\u044b) &#8212; \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434\u0430, \u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. <\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043f\u043e \u0437\u0430\u0445\u0432\u0430\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u0440\u044f\u043c\u043e \u0432 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u0448\u0438\u043d\u0443 \u041f\u0438\u0442\u043e\u043d\u0430. <\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0430 \u041f\u0438\u0442\u043e\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439. <\/p>\n<\/li>\n<\/ol>\n<h3>Java<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0448\u043b\u0430 \u043f\u043e\u0440\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 Java. \u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c openjdk 19. <\/p>\n<pre><code class=\"java\">import java.util.ArrayList; import java.util.concurrent.atomic.*;   class Example {     public static void caller3(ArrayList&lt;Integer> a, AtomicInteger b, AtomicBoolean boo) {         a.forEach((i) -> {             if (i > b.get()) {                 System.out.println(i);                 boo.set(true);             } else {                 b.decrementAndGet();                 boo.set(false);             }         });     } }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0431\u0430\u0439\u0442-\u043a\u043e\u0434:<\/p>\n<pre><code class=\"java\">class Example {    public static void caller3(java.util.ArrayList&lt;java.lang.Integer>, java.util.concurrent.atomic.AtomicInteger, java.util.concurrent.atomic.AtomicBoolean);        0: aload_0        1: aload_1        2: aload_2        3: invokedynamic #7,  0              \/\/ InvokeDynamic #0:accept:(Ljava\/util\/concurrent\/atomic\/AtomicInteger;Ljava\/util\/concurrent\/atomic\/AtomicBoolean;)Ljava\/util\/function\/Consumer;        8: invokevirtual #11                 \/\/ Method java\/util\/ArrayList.forEach:(Ljava\/util\/function\/Consumer;)V       11: return     private static void lambda$caller3$0(java.util.concurrent.atomic.AtomicInteger, java.util.concurrent.atomic.AtomicBoolean, java.lang.Integer);        0: aload_2        1: invokevirtual #17                 \/\/ Method java\/lang\/Integer.intValue:()I        4: aload_0        5: invokevirtual #23                 \/\/ Method java\/util\/concurrent\/atomic\/AtomicInteger.get:()I        8: if_icmple     26       11: getstatic     #28                 \/\/ Field java\/lang\/System.out:Ljava\/io\/PrintStream;       14: aload_2       15: invokevirtual #34                 \/\/ Method java\/io\/PrintStream.println:(Ljava\/lang\/Object;)V       18: aload_1       19: iconst_1       20: invokevirtual #40                 \/\/ Method java\/util\/concurrent\/atomic\/AtomicBoolean.set:(Z)V       23: goto          36       26: aload_0       27: invokevirtual #46                 \/\/ Method java\/util\/concurrent\/atomic\/AtomicInteger.decrementAndGet:()I       30: pop       31: aload_1       32: iconst_0       33: invokevirtual #40                 \/\/ Method java\/util\/concurrent\/atomic\/AtomicBoolean.set:(Z)V       36: return  }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0442\u0430\u043b\u0430 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u044f\u043c\u0431\u0434\u0430 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043d\u0430\u0440\u0443\u0436\u0438, \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u0438 \u0432\u043e \u0432\u0442\u043e\u0440\u044b\u0445, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>ArrayList::forEach<\/code>, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0447\u0442\u043e, \u0438 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442 <code>Consumer&lt;Integer><\/code>. \u0421\u0435\u0439\u0447\u0430\u0441 \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f (\u044d\u0442\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0442\u0435\u043c\u0430 \u0434\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/jp-wang.github.io\/deep-into-lambda2\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>), \u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u0437\u0430 \u043a\u043b\u0430\u0441\u0441 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0441\u0440\u0435\u0434\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 class \u0444\u0430\u0439\u043b\u043e\u0432. \u0412\u044b\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f JVM \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0444\u043b\u0430\u0433 <code>-jdk.internal.lambda.dumpProxyClasses<\/code> \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 JVM. \u041f\u043e\u0441\u043b\u0435 \u0434\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<pre><code class=\"java\">import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer;  \/\/ $FF: synthetic class final class Lambder$$Lambda$1 implements Consumer {     private final AtomicInteger arg$1;      private Lambder$$Lambda$1(AtomicInteger var1) {         this.arg$1 = var1;     }      public void accept(Object var1) {         Lambder.lambda$caller2$0(this.arg$1, (Integer)var1);     } }<\/code><\/pre>\n<p>\u0418\u0442\u0430\u043a, \u0432 Java \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ol>\n<li>\n<p>\u0414\u043b\u044f \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 Java \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0441\u043d\u0430\u0440\u0443\u0436\u0438, \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438. <\/p>\n<\/li>\n<li>\n<p>\u0412 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 JVM \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043b\u044f\u043c\u0431\u0434\u0430 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0445\u0440\u0430\u043d\u0438\u043c\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438. <\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442 \u044d\u0442\u043e\u0433\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441. <\/p>\n<\/li>\n<\/ol>\n<p>\u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u0432\u0438\u0434\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e final \u0438 effectively final \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 &#8212; \u043e\u043d\u0430 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u0437\u0430\u0445\u0432\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0441\u043d\u0430\u0440\u0443\u0436\u0438, \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439. <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 Java &#8212; \u044d\u0442\u043e \u043f\u043e\u0447\u0442\u0438 \u0442\u043e \u0436\u0435, \u0447\u0442\u043e \u043c\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0438 \u0432\u044b\u0448\u0435 \u043a\u0430\u043a \u0442\u0435\u043e\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u0421++, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u044b &#8212; \u044d\u0442\u043e \u043d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 Java \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u043d\u0435\u0442.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/732434\/\"> https:\/\/habr.com\/ru\/articles\/732434\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0426\u0435\u043b\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 &#8212; \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: \u0447\u0435\u043c \u043e\u043d\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0438\u0437\u0443\u0447\u0438\u0442\u044c, \u043a\u0430\u043a \u043e\u043d\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u0421++, Python 3 \u0438 Java.<\/p>\n<p>\u041d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"http:\/\/godbolt.org\/\" rel=\"noopener noreferrer nofollow\"><u>godbolt.org<\/u><\/a><u>,<\/u> \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0438 \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438\u043b\u0438 \u0431\u0430\u0439\u0442 \u043a\u043e\u0434. \u042f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0435 \u043d\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u0430 \u043d\u0430 \u044d\u0442\u043e\u043c \u0441\u0430\u0439\u0442\u0435. <\/p>\n<h3>C++<\/h3>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f? \u041c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#8212; \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u044f\u0437\u044b\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0421++, \u043f\u0435\u0440\u0435\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 \u0435\u0451 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u0438\u043f\u043e\u0432 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0435 \u043e\u0434\u043d\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0434\u0440\u0443\u0433\u0443\u044e, \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u043c \u0444\u0430\u0439\u043b\u0435. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0436\u0435 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0451\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u043a\u043e\u0439 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u0430\u043a\u0430\u044f, \u0447\u0442\u043e \u044d\u0442\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 calling conventions. <\/p>\n<p>\u041e\u043a\u0440\u043e\u043c\u044f \u043e\u0431\u044b\u043a\u043d\u043e\u0432\u0435\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432 \u0421++ \u0435\u0441\u0442\u044c \u0438 \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u041a\u0430\u043a \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u043e, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 &#171;\u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c&#187; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0442\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b, \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0438\u043b\u0438 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 (\u0438\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0438\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043d\u0438\u0445). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441 \u043b\u044f\u043c\u0431\u0434\u0430\u043c\u0438 \u043d\u0430 \u0421++ \u0438 \u043d\u0430 \u0442\u043e, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f. \u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c gcc 12.2 \u0441 \u0444\u043b\u0430\u0433\u043e\u043c <code>-Os<\/code> (\u0447\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0442\u0435\u043c \u043f\u0440\u043e\u0449\u0435 \u0435\u0433\u043e \u0447\u0438\u0442\u0430\u0442\u044c). <\/p>\n<pre><code class=\"cpp\">#include &lt;vector> #include &lt;cstdio>  \/\/ extern so that it won`t be inlined \/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u043a\u0430\u043a extern, \u0447\u0442\u043e\u0431\u044b \u0435\u0451 \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e \u0437\u0430\u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c extern void for_each(const std::vector&lt;int>&amp; vec, void (*func) (int));  void example(const std::vector&lt;int>&amp; vec) {     for_each(vec, [] (int n) {         printf(\"%d\\n\", n);     }); }<\/code><\/pre>\n<pre><code class=\"assembly\">.LC0:         .string \"%d\\n\" example(std::vector&lt;int, std::allocator&lt;int> > const&amp;)::{lambda(int)#1}::_FUN(int):         movl    %edi, %esi         xorl    %eax, %eax         movl    $.LC0, %edi         jmp     printf example(std::vector&lt;int, std::allocator&lt;int> > const&amp;):         movl    $example(std::vector&lt;int, std::allocator&lt;int> > const&amp;)::{lambda(int)#1}::_FUN(int), %esi         jmp     for_each(std::vector&lt;int, std::allocator&lt;int> > const&amp;, void (*)(int)) \/\/ note that using jmp instead of call is an optimization; the called  \/\/ function will return to the callee of the current function, skipping `example`<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0435 \u0432\u0438\u0434\u0438\u043c: \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u0431\u044b\u043b\u0430 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (\u0442\u043e \u0435\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u043c\u044b \u0431\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0442\u0430\u043a\u043e\u0433\u043e \u0436\u0435 \u0442\u0438\u043f\u0430 \u0438 \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u0442\u0435\u043b\u043e\u043c, \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440 \u0431\u044b\u043b \u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u0436\u0435). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0433\u0434\u0435 \u043b\u044f\u043c\u0431\u0434\u0430 \u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u043d\u0430\u0440\u0443\u0436\u0438. <\/p>\n<pre><code class=\"cpp\">#include &lt;vector> #include &lt;cstdio>  extern void for_each(const std::vector&lt;int>&amp; vec, void (*func) (int));  void example(const std::vector&lt;int>&amp; vec, int threshold) {     for_each(vec, [threshold] (int n) {         if (n > threshold) {             printf(\"%d\\n\", n);         }     }); }<\/code><\/pre>\n<p>\u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u044d\u0442\u043e \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"cpp\">&lt;source>: In function 'void example(const std::vector&lt;int>&amp;, int)': &lt;source>:7:19: error: cannot convert 'example(const std::vector&lt;int>&amp;, int)::&lt;lambda(int)>' to 'void (*)(int)'     7 |     for_each(vec, [threshold] (int n) {       |                   ^~~~~~~~~~~~~~~~~~~~~       |                   |       |                   example(const std::vector&lt;int>&amp;, int)::&lt;lambda(int)>     8 |         if (n > threshold) {       |         ~~~~~~~~~~~~~~~~~~~~     9 |             printf(\"%d\\n\", n);       |             ~~~~~~~~~~~~~~~~~~    10 |         }       |         ~              11 |     });       |     ~               &lt;source>:4:58: note:   initializing argument 2 of 'void for_each(const std::vector&lt;int>&amp;, void (*)(int))'     4 | extern void for_each(const std::vector&lt;int>&amp; vec, void (*func) (int));       |                                                   ~~~~~~~^~~~~~~~~~~ Compiler returned: 1<\/code><\/pre>\n<p>\u0412\u044b\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u043d\u0430\u0440\u0443\u0436\u0438, \u0438\u043c\u0435\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0442\u0438\u043f, \u0447\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0435, <code>example(const std::vector&lt;int>&amp;, int)::&lt;lambda(int)><\/code>, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0438\u043f \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u0433\u0434\u0435 \u043e\u043d\u0430 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430. <\/p>\n<p>\u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0436\u043d\u044b\u0445 \u0432\u044b\u0432\u043e\u0434\u0430. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u0430\u044f \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e (\u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432\u044b\u0448\u0435), \u044d\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0418 \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0441\u043d\u0430\u0440\u0443\u0436\u0438, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0442\u0438\u043f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c (\u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#8212; \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0430). \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043d\u043e\u0432\u043e\u0439 \u043b\u044f\u043c\u0431\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">#include &lt;vector> #include &lt;cstdio>  template &lt;typename Callable> void __attribute__ ((noinline)) for_each(const std::vector&lt;int>&amp; vec, Callable func) {     for (const auto&amp; elem : vec) {         func(elem);     } }  void example(const std::vector&lt;int>&amp; vec, int threshold) {     for_each(vec, [threshold] (int n) {         if (n > threshold) {             printf(\"%d\\n\", n);         }     }); }<\/code><\/pre>\n<pre><code class=\"assembly\">.LC0:         .string \"%d\\n\" void for_each&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}):         pushq   %r12         pushq   %rbp         movl    %esi, %ebp         pushq   %rbx         movq    8(%rdi), %r12         movq    (%rdi), %rbx .L2:         cmpq    %rbx, %r12         je      .L7         movl    (%rbx), %esi         cmpl    %ebp, %esi         jle     .L3         movl    $.LC0, %edi         xorl    %eax, %eax         call    printf .L3:         addq    $4, %rbx         jmp     .L2 .L7:         popq    %rbx         popq    %rbp         popq    %r12         ret example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int):         jmp     void for_each&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1})<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>for_each<\/code> \u0431\u044b\u043b\u0430 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u0438 \u043d\u0430\u0448\u0430 \u043b\u044f\u043c\u0431\u0434\u0430 \u0442\u0443\u0434\u0430 \u0437\u0430\u0438\u043d\u043b\u0430\u0439\u043d\u0438\u043b\u0430\u0441\u044c &#8212; \u0430 <code>for_each<\/code> \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0438 \u0447\u0438\u0441\u043b\u043e. <\/p>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u0421++ \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u0438 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043b\u044f\u043c\u0431\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u0441\u044f \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<p>\u041d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430! \u041c\u044b (\u0432\u0440\u043e\u0434\u0435) \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c \u043b\u044f\u043c\u0431\u0434\u044b, \u043d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0434\u043e\u0440\u043e\u0433\u0438\u043c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u044f <code>-Os<\/code>, \u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c \u0435\u0451 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043b\u044f\u043c\u0431\u0434\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<pre><code class=\"cpp\">#include &lt;vector> #include &lt;cstdio>  template &lt;typename Callable> void __attribute__ ((noinline)) for_each(const std::vector&lt;int>&amp; vec, Callable func) {     for (const auto&amp; elem : vec) {         func(elem);     } }  template &lt;typename Callable> void __attribute__ ((noinline)) for_each2(const std::vector&lt;int>&amp; vec, Callable func) {     for (auto iter = vec.rbegin(); iter != vec.rend(); iter++) {         func(*iter);     } }  void example(const std::vector&lt;int>&amp; vec, int threshold) {     auto lambda = [threshold] (int n) {         if (n > threshold) {             printf(\"%d\\n\", n);             printf(\"number: %d\", n);             printf(\"previous number: %d\", --n);             printf(\"next number: %d\", n + 2);         }     };     for_each(vec, lambda);     for_each2(vec, lambda); }<\/code><\/pre>\n<pre><code class=\"assembly\">.LC0:         .string \"%d\\n\" .LC1:         .string \"number: %d\" .LC2:         .string \"previous number: %d\" .LC3:         .string \"next number: %d\" example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}::operator()(int) const [clone .part.0]:         pushq   %rbx         movl    %edi, %esi         movl    %edi, %ebx         xorl    %eax, %eax         movl    $.LC0, %edi         call    printf         movl    %ebx, %esi         movl    $.LC1, %edi         xorl    %eax, %eax         call    printf         leal    -1(%rbx), %esi         movl    $.LC2, %edi         xorl    %eax, %eax         call    printf         leal    1(%rbx), %esi         movl    $.LC3, %edi         xorl    %eax, %eax         popq    %rbx         jmp     printf void for_each&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}):         pushq   %r12         pushq   %rbp         movl    %esi, %ebp         pushq   %rbx         movq    8(%rdi), %r12         movq    (%rdi), %rbx .L4:         cmpq    %rbx, %r12         je      .L9         movl    (%rbx), %edi         cmpl    %ebp, %edi         jle     .L5         call    example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}::operator()(int) const [clone .part.0] .L5:         addq    $4, %rbx         jmp     .L4 .L9:         popq    %rbx         popq    %rbp         popq    %r12         ret void for_each2&lt;example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}>(std::vector&lt;int, std::allocator&lt;int> > const&amp;, example(std::vector&lt;int, std::allocator&lt;int> > const&amp;, int)::{lambda(int)#1}):         pushq   %r12         movl    %esi, %r12d         pushq   %rbp         movq    %rdi, %rbp         pushq   %rbx         movq    8(%rdi), %rbx .L11:         cmpq    %rbx, 0(%rbp)         je      .L15         movl    -4(%rbx), %edi         cmpl    %r12d, %edi         jle     .L12         call    example(std::vector&lt;int, std::allocator&lt;int> > const&amp;<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-403270","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/403270","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=403270"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/403270\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=403270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=403270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=403270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}