{"id":330687,"date":"2022-03-15T15:01:16","date_gmt":"2022-03-15T15:01:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=330687"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=330687","title":{"rendered":"<span>\u0428\u0430\u0431\u043b\u043e\u043d\u044b C++: \u043a\u0430\u043a \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e std::tuple \u2014 \u043e\u0441\u043d\u043e\u0432\u044b<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c36\/946\/e99\/c36946e9990c05eb6071a8ff528bd12e.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c36\/946\/e99\/c36946e9990c05eb6071a8ff528bd12e.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0446\u0438\u043a\u043b\u0430 for \u0441 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u043f\u0440\u044f\u043c\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041d\u043e \u0447\u0442\u043e \u043d\u0430\u0441\u0447\u0435\u0442 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 (<code>std::tuple<\/code>)? \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043d\u0435 \u201c\u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u201d \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0435\u043c\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u043a\u043e\u0440\u0442\u0435\u0436\u0430.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0440\u0442\u0435\u0436:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, 3.14, 42, \"hello\"}; printTuple(tp);<\/code><\/pre>\n<p>\u041c\u044b \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u044b\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"cpp\">(10, 20, 3.14, 42, hello)<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0436\u0435 \u043d\u0430\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u200b\u200b\u0444\u0443\u043d\u043a\u0446\u0438\u044e printTuple?<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c!<\/p>\n<p><em>\u042d\u0442\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c, \u0433\u0434\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0441\u043d\u043e\u0432\u044b. \u0412\u043e <\/em><a href=\"https:\/\/www.cppstories.com\/2022\/tuple-iteration-apply\/\"><em>\u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/em><\/a><em> \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u0431 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u0445, <\/em><code>std::apply<\/code><em> \u0438 \u043c\u043d\u043e\u0433\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u043c.<\/em><\/p>\n<h3>\u041e\u0441\u043d\u043e\u0432\u044b<\/h3>\n<p><code>std::tuple<\/code> (\u043a\u043e\u0440\u0442\u0435\u0436) \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0440\u0430\u0437\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, \u0435\u0433\u043e \u043c\u043b\u0430\u0434\u0448\u0438\u0439 \u0431\u0440\u0430\u0442 \u2014 <code>std::pair<\/code> (\u043f\u0430\u0440\u0430) \u2014 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, &lt;T, U>.<\/p>\n<pre><code class=\"cpp\">std::pair&lt;int, double> intDouble { 10, 42.42 }; \/\/ \u0438\u043b\u0438 with CTAD, C++17: std::pair deducedIntDouble { 10, 42.42 }; \/\/ \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432!<\/code><\/pre>\n<p><code>std::tuple<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0422\u0430\u043a \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>std::pair<\/code> , \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432\/\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"cpp\">std::tuple&lt;int, double, const char*> tup {42, 10.5, \"hello\"}; \/\/ \u0438\u043b\u0438 with CTAD, C++17: std::tuple deducedTup {42, 10.5, \"hello\"}; \/\/ \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043f\u0430\u0440\u044b, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c <code>.first<\/code> \u0438\u043b\u0438 <code>.second<\/code> \u044d\u043b\u0435\u043c\u0435\u043d\u0442:<\/p>\n<pre><code class=\"cpp\">std::pair intDouble { 10, 42.42 };  intDouble.first *= 10;<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0439, \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043d\u0438 <code>.first<\/code>, \u043d\u0438 <code>.second<\/code>, \u043d\u0438 <code>.third<\/code>&#8230; \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 <code>std::get<\/code>:<\/p>\n<pre><code class=\"cpp\">#include &lt;tuple> #include &lt;iostream>  int main() {     std::tuple tp {42, 10.5, \"hello\"};        \/\/ \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443:     std::get&lt;0>(tp) *= 100;     std::cout &lt;&lt; std::get&lt;0>(tp) &lt;&lt; '\\n';     std::cout &lt;&lt; std::get&lt;2>(tp) &lt;&lt; '\\n';          \/\/ \u043f\u043e \u0442\u0438\u043f\u0443:     std::cout &lt;&lt; std::get&lt;double>(tp) &lt;&lt; '\\n'; }<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/49979Kzo8\"><u>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 @Compiler Explorer<\/u><\/a><\/p>\n<h4>\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e \u043d\u0435\u043c\u0443 \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c?\u00a0<\/h4>\n<p>\u041d\u0443 \u0447\u0442\u043e \u0436, \u0442\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0441 \u043e\u0441\u043d\u043e\u0432\u0430\u043c\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u0440\u0442\u0435\u0436\u0430.<\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\/\u0442\u0438\u043f\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u042d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442 \u043a\u043e\u0440\u0442\u0435\u0436 \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430, \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u0430\u043a <code>std::vector<\/code>, \u043a\u0443\u0434\u0430 \u043c\u044b \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043a\u043e\u0440\u0442\u0435\u0436\u0443, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u201c\u0436\u0435\u043b\u0430\u043d\u043d\u044b\u0439\u201d \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">\/\/ \u043a\u0430\u043a \u0431\u044b \u043c\u044b \u0445\u043e\u0442\u0435\u043b\u0438: std::tuple tp {42, 10.5, \"hello\"}; for (auto&amp; elem : tp)     std::cout &lt;&lt; elem &lt;&lt; \", \";<\/code><\/pre>\n<p>\u0412\u043e \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"cpp\">std::tuple tp {42, 10.5, \"hello\"}; std::cout &lt;&lt; std::get&lt;0>(tp) &lt;&lt; \", \"; std::cout &lt;&lt; std::get&lt;1>(tp) &lt;&lt; \", \"; std::cout &lt;&lt; std::get&lt;2>(tp) &lt;&lt; \", \";<\/code><\/pre>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u043a\u043e\u0440\u0442\u0435\u0436 \u0432 \u0440\u044f\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <code>std::get&lt;id><\/code> \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043f\u043e \u0435\u0433\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0438 (id). \u041f\u043e\u0437\u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 <code>std::cout<\/code> \u0438\u043b\u0438 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 (\u0434\u043b\u044f \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438).<\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044f\u0437\u044b\u043a \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u043a\u0438\u0435 \u0446\u0438\u043a\u043b\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438\u2026 \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u043f\u043e\u043a\u0430 (\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u043d\u0438\u0437\u0443).<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443\u0442\u044c \u043a \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u043c\u0430\u0433\u0438\u0438.<\/p>\n<h3>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u00a0<\/h3>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u0432\u0435\u0441\u0442\u0438:<\/p>\n<pre><code class=\"cpp\">template &lt;typename T> void printElem(const T&amp; x) {     std::cout &lt;&lt; x &lt;&lt; ','; };  template &lt;typename TupleT, std::size_t... Is> void printTupleManual(const TupleT&amp; tp) {     (printElem(std::get&lt;Is>(tp)), ...); }<\/code><\/pre>\n<p>\u0418 \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u0448\u0430 \u0438\u0441\u043a\u043e\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0444\u043e\u0440\u043c\u0443:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, \"hello\"}; printTupleManual&lt;decltype(tp), 0, 1, 2>(tp);<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/ejqGab1MW\"><u>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 @Compiler Explorer<\/u><\/a><\/p>\n<p>\u0427\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442?<\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0442\u0438\u043f\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>printTupleManual<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0435\u0442\u0438\u043f\u043e\u0432\u044b\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u2014 <code>variadic<\/code> \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 <code>size_t<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0414\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>tp<\/code> \u044d\u0442\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <code>decltype<\/code>. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, \"hello\"}; printTupleManual&lt;std::tuple&lt;int, int, const char*>, 0, 1, 2>(tp);<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, <code>decltype<\/code> \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u043d\u0430\u043c \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/decltype\">Cppreference &#8212; decltype<\/a>.<\/p>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u0441\u0430\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0432\u0435\u0440\u0442\u043a\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 (\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0443\u044e \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++17), \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u044d\u0442\u043e\u0442 variadic \u043d\u0430\u0431\u043e\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0437\u0430\u043f\u044f\u0442\u043e\u0439.<\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u043e\u0440\u043c\u0435:<\/p>\n<pre><code class=\"cpp\">void printTupleManual&lt;std::tuple&lt;int, int, const char *>, 0, 1, 2>     (const std::tuple&lt;int, int, const char *> &amp; tp) {   printElem(get&lt;0>(tp)), (printElem(get&lt;1>(tp)), printElem(get&lt;2>(tp))); }<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u201c\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u201d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>CppInsights<\/code> \u2014 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0434\u0435\u043c\u043e \u043f\u043e <a href=\"https:\/\/cppinsights.io\/s\/9c8a6aa6\">\u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u0432\u0435\u0440\u0442\u043a\u0430\u043c (fold expressions) \u043c\u044b \u0441\u0442\u0430\u043b\u0438 \u043d\u0430 \u0448\u0430\u0433 \u0431\u043b\u0438\u0436\u0435 \u043a \u0438\u0441\u043a\u043e\u043c\u043e\u0439 \u043d\u0430\u043c\u0438 \u0444\u043e\u0440\u043c\u0435 \u0446\u0438\u043a\u043b\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438!<\/p>\n<h3>\u041f\u043e\u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0439\u0442\u0435 index_sequence\u00a0<\/h3>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435 \u0432\u044f\u0436\u0435\u0442\u0441\u044f \u0441 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c\u044e \u0438 \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d\u043e \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u041c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u044d\u0442\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043a\u043e\u0440\u0442\u0435\u0436\u0430?<\/p>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0443\u0436\u043d\u043e, \u0442\u0430\u043a \u044d\u0442\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b:<\/p>\n<pre><code class=\"cpp\">\/\/ \u0434\u043b\u044f \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 N \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a 0, 1, ..., N-1<\/code><\/pre>\n<p>\u042d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438, \u0438, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++14, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>index_sequence<\/code>. \u042d\u0442\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0432 \u0432\u0438\u0434\u0435 \u043d\u0435\u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0430:<\/p>\n<pre><code class=\"cpp\">template&lt; class T, T... Ints >  class integer_sequence;  template&lt;std::size_t... Ints> using index_sequence = std::integer_sequence&lt;std::size_t, Ints...>;<\/code><\/pre>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 C++ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 <code>std::integer_sequence&lt;T, T... Ints><\/code>, \u0430 <code>std::index_sequence<\/code> \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e <code>integer_sequence<\/code> \u043f\u043e <code>size_t<\/code>. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/utility\/integer_sequence\">@cppreference.com<\/a>.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 \u0432 \u0442\u0430\u043a\u0443\u044e \u0444\u043e\u0440\u043c\u0443:<\/p>\n<pre><code class=\"cpp\">template &lt;typename T> void printElem(const T&amp; x) {     std::cout &lt;&lt; x &lt;&lt; ','; };  template &lt;typename TupleT, std::size_t... Is> void printTupleManual(const TupleT&amp; tp, std::index_sequence&lt;Is...>) {     (printElem(std::get&lt;Is>(tp)), ...); }<\/code><\/pre>\n<p>\u0418 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, \"hello\"}; printTupleManual(tp, std::index_sequence&lt;0, 1, 2>{});<\/code><\/pre>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>make_index_sequence<\/code>:<\/p>\n<pre><code class=\"cpp\">printTupleManual(tp, std::make_index_sequence&lt;3>{});<\/code><\/pre>\n<p>\u0418 \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0440\u0442\u0435\u0436\u0430:<\/p>\n<pre><code class=\"cpp\">printTupleManual(tp, std::make_index_sequence&lt;std::tuple_size&lt;decltype(tp)>::value>{});<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u2014 <code>tuple_size_v<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0440\u043e\u0447\u0435:<\/p>\n<pre><code class=\"cpp\">printTupleManual(tp, std::make_index_sequence&lt;std::tuple_size_v&lt;decltype(tp)>>{});<\/code><\/pre>\n<p>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">template &lt;typename T> void printElem(const T&amp; x) {     std::cout &lt;&lt; x &lt;&lt; ','; };  template &lt;typename TupleT, std::size_t... Is> void printTupleManual(const TupleT&amp; tp, std::index_sequence&lt;Is...>) {     (printElem(std::get&lt;Is>(tp)), ...); }  template &lt;typename TupleT, std::size_t TupSize = std::tuple_size_v&lt;TupleT>> void printTupleGetSize(const TupleT&amp; tp) {     printTupleManual(tp, std::make_index_sequence&lt;TupSize>{}); }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0435 \u0432\u044b\u0437\u043e\u0432 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0447\u0435\u043d\u044c \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, \"hello\"}; printTupleGetSize(tp);<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/rEM8esWzn\"><u>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u043e\u0434 \u0432 @Compiler Explorer<\/u><\/a><\/p>\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u201c\u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044b\u0439\u201d \u043a\u043e\u0434 \u0432 C++ Insights, \u043f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u043e <a href=\"https:\/\/cppinsights.io\/s\/423db0e1\">\u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430\u0448 \u0432\u044b\u0437\u043e\u0432 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432:<\/p>\n<pre><code class=\"cpp\">void printTupleGetSize&lt;std::tuple&lt;int, int, const char *>, 3>      (const std::tuple&lt;int, int, const char *> &amp; tp) {   printTupleManual(tp, std::integer_sequence&lt;unsigned long, 0, 1, 2>{}); }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, <code>make_index_sequence<\/code> \u0431\u044b\u043b \u044d\u043b\u0435\u0433\u0435\u043d\u0442\u043d\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442 \u0432 <code>std::integer_sequence&lt;unsigned long, 0, 1, 2>{}<\/code>.<\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434 std::tuple \u00a0<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u043a\u043e\u0440\u0442\u0435\u0436\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0445 \u0432 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.<\/p>\n<pre><code class=\"cpp\">template &lt;typename TupleT, std::size_t... Is> void printTupleImp(const TupleT&amp; tp, std::index_sequence&lt;Is...>) {     size_t index = 0;     auto printElem = [&amp;index](const auto&amp; x) {         if (index++ > 0)              std::cout &lt;&lt; \", \";         std::cout &lt;&lt; x;     };      std::cout &lt;&lt; \"(\";     (printElem(std::get&lt;Is>(tp)), ...);     std::cout &lt;&lt; \")\"; }  template &lt;typename TupleT, std::size_t TupSize = std::tuple_size_v&lt;TupleT>> void printTuple(const TupleT&amp; tp) {     printTupleImp(tp, std::make_index_sequence&lt;TupSize>{}); }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0432\u043d\u0443\u0442\u0440\u0438 <code>printTupleImp<\/code> \u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043b <code>printElem<\/code> \u0432 \u043b\u044f\u043c\u0431\u0434\u0443. \u042d\u0442\u043e\u0442 \u0448\u0430\u0433 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043d\u0435 \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c. \u041c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0434\u043e\u043b\u0436\u0435\u043d \u043b\u0438 \u044f \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0435:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, \"hello\"}; printTuple(tp);<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/K6KdYG6zK\"><u>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 @Compiler Explorer<\/u><\/a><\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e!<\/p>\n<p>\u041d\u043e\u2026 \u043a\u0430\u043a \u043d\u0430\u0441\u0447\u0435\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0435 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>&lt;&lt;<\/code> ? \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0435\u0441\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 <code>std::cout<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u0441\u043b\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u0440\u0442\u0435\u0436 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<h3>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 &lt;&lt; \u00a0\u00a0\u00a0\u00a0<\/h3>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>ostream<\/code> :<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;ostream> #include &lt;tuple>  template &lt;typename TupleT, std::size_t... Is> std::ostream&amp; printTupleImp(std::ostream&amp; os, const TupleT&amp; tp, std::index_sequence&lt;Is...>) {     size_t index = 0;     auto printElem = [&amp;index, &amp;os](const auto&amp; x) {         if (index++ > 0)              os &lt;&lt; \", \";         os &lt;&lt; x;     };      os &lt;&lt; \"(\";     (printElem(std::get&lt;Is>(tp)), ...);     os &lt;&lt; \")\";     return os; }  template &lt;typename TupleT, std::size_t TupSize = std::tuple_size&lt;TupleT>::value> std::ostream&amp; operator &lt;&lt;(std::ostream&amp; os, const TupleT&amp; tp) {     return printTupleImp(os, tp, std::make_index_sequence&lt;TupSize>{});  }  int main() {     std::tuple tp { 10, 20, \"hello\"};     std::cout &lt;&lt; tp &lt;&lt; '\\n'; }<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/jn8scavWf\"><u>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 @Compiler Explorer<\/u><\/a><\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u00a0\u00a0\u00a0<\/h3>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0430\u043c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e?<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;ostream> #include &lt;tuple>  template &lt;typename TupleT, std::size_t... Is> std::ostream&amp; printTupleImp(std::ostream&amp; os, const TupleT&amp; tp, std::index_sequence&lt;Is...>) {     auto printElem = [&amp;os](const auto&amp; x, size_t id) {         if (id > 0)              os &lt;&lt; \", \";         os &lt;&lt; id &lt;&lt; \": \" &lt;&lt; x;     };      os &lt;&lt; \"(\";     (printElem(std::get&lt;Is>(tp), Is), ...);     os &lt;&lt; \")\";     return os; }  template &lt;typename TupleT, std::size_t TupSize = std::tuple_size&lt;TupleT>::value> std::ostream&amp; operator &lt;&lt;(std::ostream&amp; os, const TupleT&amp; tp) {     return printTupleImp(os, tp, std::make_index_sequence&lt;TupSize>{});  }  int main() {     std::tuple tp { 10, 20, \"hello\"};     std::cout &lt;&lt; tp &lt;&lt; '\\n'; }<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/TPP3qGjPe\"><u>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 @Compiler Explorer<\/u><\/a><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>index<\/code> \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u044e \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438\u0437 \u0441\u0432\u0435\u0440\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0432\u044b\u0432\u043e\u0434\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<pre><code class=\"cpp\">(0: 10, 1: 20, 2: hello)<\/code><\/pre>\n<p>\u0425\u043e\u0442\u0438\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u0435?<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 <code>std::format<\/code>, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043c\u043e\u044e \u0441\u0442\u0430\u0442\u044c\u044e: <a href=\"https:\/\/www.patreon.com\/posts\/61665073\">\u041a\u0430\u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u044b \u0438 \u043a\u043e\u0440\u0442\u0435\u0436\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e std::format (~1450 \u0441\u043b\u043e\u0432)<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0434\u043b\u044f \u043f\u0430\u0442\u0440\u043e\u043d\u043e\u0432 <em>C++ Stories Premium<\/em> \u043d\u0430 \u043f\u0430\u0442\u0440\u0435\u043e\u043d\u0435. \u041e\u0446\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 Premium \u043f\u0430\u0442\u0440\u043e\u043d\u0430\u0436\u0430 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/www.cppstories.com\/p\/extra-patreon-content\/\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u00a0<\/h3>\n<p>\u042d\u0442\u043e \u0431\u044b\u043b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442!<\/p>\n<p>\u0417\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0448\u0430\u0433\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u043c\u044b \u043f\u0440\u043e\u0448\u043b\u0438 \u043f\u0443\u0442\u044c \u043e\u0442 \u043e\u0441\u043d\u043e\u0432 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 \u043a \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438 \u0441 <code>std::index_sequence<\/code>. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u0432\u0435\u0440\u0442\u043e\u0447\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c \u0441 C++17, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u043d\u0430\u0448 \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0440\u0445 \u043d\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<p>\u041c\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043b\u0438\u0441\u044c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0432\u043e\u0434\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438 \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u0430. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u0449\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0443\u0434\u043e\u0431\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>std::apply<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0430\u0441\u0442 \u043d\u0430\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432\u0442\u043e\u0440\u0443\u044e \u0447\u0430\u0441\u0442\u044c: <a href=\"https:\/\/www.cppstories.com\/2022\/tuple-iteration-apply\/\">\u0428\u0430\u0431\u043b\u043e\u043d\u044b C++: \u043a\u0430\u043a \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e std::tuple &#8212; std::apply \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435 \u2014 C++ Stories<\/a>.<\/p>\n<h4>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u0432\u0430\u043c<\/h4>\n<p>\u041c\u043d\u0435 \u0442\u0430\u043a\u0436\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u0432\u0430\u0448\u0438\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 \u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u043d\u0438\u043c.<\/p>\n<p>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0432\u0430\u0448\u0438\u043c\u0438 \u043c\u044b\u0441\u043b\u044f\u043c\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043f\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0435\u0439.<\/p>\n<h4>for \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438<\/h4>\n<p>\u042f \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u043b, \u0447\u0442\u043e C++ \u043d\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u0446\u0438\u043a\u043b\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043d\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <a href=\"https:\/\/wg21.link\/p1306r1\">P1306<\/a> \u2014 \u201cExpansion statements\u201d. \u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0438, \u043d\u043e \u0432\u0440\u044f\u0434 \u043b\u0438 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0432 C++23.<\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"cpp\">auto tup = std::make_tuple(0, \u2018a\u2019, 3.14); for... (auto elem : tup)     std::cout &lt;&lt; elem &lt;&lt; std::endl;<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043d\u0430 <a href=\"https:\/\/github.com\/cplusplus\/papers\/issues\/156\">@Github\/cpp\/papers<\/a>.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u044f<\/h3>\n<p>\u041a\u043d\u0438\u0433\u0438:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/amzn.to\/3GMx8Uu\">Effective Modern C++<\/a> by Scott Meyers.<\/p>\n<\/li>\n<li>\n<p><a href=\"http:\/\/amzn.to\/2wtoENU\">C++ Templates: The Complete Guide (2nd Edition)<\/a> by David Vandevoorde, Nicolai M. Josuttis, Douglas Gregor.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0442\u0430\u0442\u044c\u0438 \u0438 \u0441\u0441\u044b\u043b\u043a\u0438:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/www.fluentcpp.com\/2021\/03\/12\/cpp-fold-expressions\/\">C++ Fold Expressions 101 &#8212; Fluent C++<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20200622-00\/?p=103900\">Mundane std::tuple tricks: Getting started &#8212; The Old New Thing<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.fluentcpp.com\/2021\/03\/05\/stdindex_sequence-and-its-improvement-in-c20\/\">std::index_sequence and its Improvement in C++20 &#8212; Fluent C++<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/41199709\/is-there-a-tuple-for-each-that-returns-a-tuple-of-all-values-returned-from-the\">c++ &#8212; Is there a tuple for_each() that returns a tuple of all values returned from the functions invoked? &#8212; Stack Overflow<\/a><\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0432 OTUS \u043f\u0440\u043e\u0439\u0434\u0435\u0442 demo-\u0443\u0440\u043e\u043a \u043f\u043e \u043e\u0441\u043d\u043e\u0432\u0430\u043c C++, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0431\u0441\u0443\u0434\u0438\u043c:<\/p>\n<ul>\n<li>\n<p>\u0427\u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0443\u0442\u044c \u00ab\u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 C++\u00bb? <\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u0438\u0435 \u0435\u0441\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0447\u0435\u0440\u0442\u044b \u0443 \u044d\u0442\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430? <\/p>\n<\/li>\n<li>\n<p>\u0412 \u0447\u0435\u043c \u0435\u0433\u043e \u0441\u0438\u043b\u044c\u043d\u044b\u0435 \u0438 \u0441\u043b\u0430\u0431\u044b\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b?<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0432\u0441\u0435\u0445 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445, \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f<a href=\"https:\/\/otus.pw\/y80F\/\"> \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435.<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/company\/otus\/blog\/655715\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/655715\/<\/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_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0446\u0438\u043a\u043b\u0430 for \u0441 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u043c \u043f\u0440\u044f\u043c\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041d\u043e \u0447\u0442\u043e \u043d\u0430\u0441\u0447\u0435\u0442 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 (<code>std::tuple<\/code>)? \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043d\u0435 \u201c\u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u201d \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0435\u043c\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u043a\u043e\u0440\u0442\u0435\u0436\u0430.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0440\u0442\u0435\u0436:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, 3.14, 42, \"hello\"}; printTuple(tp);<\/code><\/pre>\n<p>\u041c\u044b \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u044b\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"cpp\">(10, 20, 3.14, 42, hello)<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0436\u0435 \u043d\u0430\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u200b\u200b\u0444\u0443\u043d\u043a\u0446\u0438\u044e printTuple?<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c!<\/p>\n<p><em>\u042d\u0442\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c, \u0433\u0434\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0441\u043d\u043e\u0432\u044b. \u0412\u043e <\/em><a href=\"https:\/\/www.cppstories.com\/2022\/tuple-iteration-apply\/\"><em>\u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/em><\/a><em> \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u0431 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u0445, <\/em><code>std::apply<\/code><em> \u0438 \u043c\u043d\u043e\u0433\u043e\u043c \u0434\u0440\u0443\u0433\u043e\u043c.<\/em><\/p>\n<h3>\u041e\u0441\u043d\u043e\u0432\u044b<\/h3>\n<p><code>std::tuple<\/code> (\u043a\u043e\u0440\u0442\u0435\u0436) \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0440\u0430\u0437\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, \u0435\u0433\u043e \u043c\u043b\u0430\u0434\u0448\u0438\u0439 \u0431\u0440\u0430\u0442 \u2014 <code>std::pair<\/code> (\u043f\u0430\u0440\u0430) \u2014 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, &lt;T, U>.<\/p>\n<pre><code class=\"cpp\">std::pair&lt;int, double> intDouble { 10, 42.42 }; \/\/ \u0438\u043b\u0438 with CTAD, C++17: std::pair deducedIntDouble { 10, 42.42 }; \/\/ \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432!<\/code><\/pre>\n<p><code>std::tuple<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0422\u0430\u043a \u0447\u0442\u043e \u044d\u0442\u043e \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>std::pair<\/code> , \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432\/\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"cpp\">std::tuple&lt;int, double, const char*> tup {42, 10.5, \"hello\"}; \/\/ \u0438\u043b\u0438 with CTAD, C++17: std::tuple deducedTup {42, 10.5, \"hello\"}; \/\/ \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043f\u0430\u0440\u044b, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c <code>.first<\/code> \u0438\u043b\u0438 <code>.second<\/code> \u044d\u043b\u0435\u043c\u0435\u043d\u0442:<\/p>\n<pre><code class=\"cpp\">std::pair intDouble { 10, 42.42 };  intDouble.first *= 10;<\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0439, \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043d\u0438 <code>.first<\/code>, \u043d\u0438 <code>.second<\/code>, \u043d\u0438 <code>.third<\/code>&#8230; \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 <code>std::get<\/code>:<\/p>\n<pre><code class=\"cpp\">#include &lt;tuple> #include &lt;iostream>  int main() {     std::tuple tp {42, 10.5, \"hello\"};        \/\/ \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443:     std::get&lt;0>(tp) *= 100;     std::cout &lt;&lt; std::get&lt;0>(tp) &lt;&lt; '\\n';     std::cout &lt;&lt; std::get&lt;2>(tp) &lt;&lt; '\\n';          \/\/ \u043f\u043e \u0442\u0438\u043f\u0443:     std::cout &lt;&lt; std::get&lt;double>(tp) &lt;&lt; '\\n'; }<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/49979Kzo8\"><u>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 @Compiler Explorer<\/u><\/a><\/p>\n<h4>\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e \u043d\u0435\u043c\u0443 \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c?\u00a0<\/h4>\n<p>\u041d\u0443 \u0447\u0442\u043e \u0436, \u0442\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0441 \u043e\u0441\u043d\u043e\u0432\u0430\u043c\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u0440\u0442\u0435\u0436\u0430.<\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\/\u0442\u0438\u043f\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u042d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442 \u043a\u043e\u0440\u0442\u0435\u0436 \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430, \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u0430\u043a <code>std::vector<\/code>, \u043a\u0443\u0434\u0430 \u043c\u044b \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043a\u043e\u0440\u0442\u0435\u0436\u0443, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u201c\u0436\u0435\u043b\u0430\u043d\u043d\u044b\u0439\u201d \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">\/\/ \u043a\u0430\u043a \u0431\u044b \u043c\u044b \u0445\u043e\u0442\u0435\u043b\u0438: std::tuple tp {42, 10.5, \"hello\"}; for (auto&amp; elem : tp)     std::cout &lt;&lt; elem &lt;&lt; \", \";<\/code><\/pre>\n<p>\u0412\u043e \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"cpp\">std::tuple tp {42, 10.5, \"hello\"}; std::cout &lt;&lt; std::get&lt;0>(tp) &lt;&lt; \", \"; std::cout &lt;&lt; std::get&lt;1>(tp) &lt;&lt; \", \"; std::cout &lt;&lt; std::get&lt;2>(tp) &lt;&lt; \", \";<\/code><\/pre>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043b\u043e\u0436\u0438\u0442\u044c \u043a\u043e\u0440\u0442\u0435\u0436 \u0432 \u0440\u044f\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <code>std::get&lt;id><\/code> \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043f\u043e \u0435\u0433\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0438 (id). \u041f\u043e\u0437\u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 <code>std::cout<\/code> \u0438\u043b\u0438 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 (\u0434\u043b\u044f \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438).<\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044f\u0437\u044b\u043a \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u043a\u0438\u0435 \u0446\u0438\u043a\u043b\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438\u2026 \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u043f\u043e\u043a\u0430 (\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u043d\u0438\u0437\u0443).<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443\u0442\u044c \u043a \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u043c\u0430\u0433\u0438\u0438.<\/p>\n<h3>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u00a0<\/h3>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u0432\u0435\u0441\u0442\u0438:<\/p>\n<pre><code class=\"cpp\">template &lt;typename T> void printElem(const T&amp; x) {     std::cout &lt;&lt; x &lt;&lt; ','; };  template &lt;typename TupleT, std::size_t... Is> void printTupleManual(const TupleT&amp; tp) {     (printElem(std::get&lt;Is>(tp)), ...); }<\/code><\/pre>\n<p>\u0418 \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u0448\u0430 \u0438\u0441\u043a\u043e\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0444\u043e\u0440\u043c\u0443:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, \"hello\"}; printTupleManual&lt;decltype(tp), 0, 1, 2>(tp);<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/ejqGab1MW\"><u>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 @Compiler Explorer<\/u><\/a><\/p>\n<p>\u0427\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442?<\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0442\u0438\u043f\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>printTupleManual<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0435\u0442\u0438\u043f\u043e\u0432\u044b\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u2014 <code>variadic<\/code> \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 <code>size_t<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0414\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>tp<\/code> \u044d\u0442\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <code>decltype<\/code>. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, \"hello\"}; printTupleManual&lt;std::tuple&lt;int, int, const char*>, 0, 1, 2>(tp);<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, <code>decltype<\/code> \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u043d\u0430\u043c \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/decltype\">Cppreference &#8212; decltype<\/a>.<\/p>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u0441\u0430\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0432\u0435\u0440\u0442\u043a\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 (\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0443\u044e \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++17), \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u044d\u0442\u043e\u0442 variadic \u043d\u0430\u0431\u043e\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0437\u0430\u043f\u044f\u0442\u043e\u0439.<\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u043e\u0440\u043c\u0435:<\/p>\n<pre><code class=\"cpp\">void printTupleManual&lt;std::tuple&lt;int, int, const char *>, 0, 1, 2>     (const std::tuple&lt;int, int, const char *> &amp; tp) {   printElem(get&lt;0>(tp)), (printElem(get&lt;1>(tp)), printElem(get&lt;2>(tp))); }<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u201c\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u201d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>CppInsights<\/code> \u2014 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0434\u0435\u043c\u043e \u043f\u043e <a href=\"https:\/\/cppinsights.io\/s\/9c8a6aa6\">\u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u0432\u0435\u0440\u0442\u043a\u0430\u043c (fold expressions) \u043c\u044b \u0441\u0442\u0430\u043b\u0438 \u043d\u0430 \u0448\u0430\u0433 \u0431\u043b\u0438\u0436\u0435 \u043a \u0438\u0441\u043a\u043e\u043c\u043e\u0439 \u043d\u0430\u043c\u0438 \u0444\u043e\u0440\u043c\u0435 \u0446\u0438\u043a\u043b\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438!<\/p>\n<h3>\u041f\u043e\u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0439\u0442\u0435 index_sequence\u00a0<\/h3>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435 \u0432\u044f\u0436\u0435\u0442\u0441\u044f \u0441 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c\u044e \u0438 \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d\u043e \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u041c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u044d\u0442\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043a\u043e\u0440\u0442\u0435\u0436\u0430?<\/p>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0443\u0436\u043d\u043e, \u0442\u0430\u043a \u044d\u0442\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b:<\/p>\n<pre><code class=\"cpp\">\/\/ \u0434\u043b\u044f \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 N \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a 0, 1, ..., N-1<\/code><\/pre>\n<p>\u042d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0430 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u043c\u0438, \u0438, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C++14, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>index_sequence<\/code>. \u042d\u0442\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0432 \u0432\u0438\u0434\u0435 \u043d\u0435\u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u0430:<\/p>\n<pre><code class=\"cpp\">template&lt; class T, T... Ints >  class integer_sequence;  template&lt;std::size_t... Ints> using index_sequence = std::integer_sequence&lt;std::size_t, Ints...>;<\/code><\/pre>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 C++ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 <code>std::integer_sequence&lt;T, T... Ints><\/code>, \u0430 <code>std::index_sequence<\/code> \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e <code>integer_sequence<\/code> \u043f\u043e <code>size_t<\/code>. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/utility\/integer_sequence\">@cppreference.com<\/a>.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 \u0432 \u0442\u0430\u043a\u0443\u044e \u0444\u043e\u0440\u043c\u0443:<\/p>\n<pre><code class=\"cpp\">template &lt;typename T> void printElem(const T&amp; x) {     std::cout &lt;&lt; x &lt;&lt; ','; };  template &lt;typename TupleT, std::size_t... Is> void printTupleManual(const TupleT&amp; tp, std::index_sequence&lt;Is...>) {     (printElem(std::get&lt;Is>(tp)), ...); }<\/code><\/pre>\n<p>\u0418 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, \"hello\"}; printTupleManual(tp, std::index_sequence&lt;0, 1, 2>{});<\/code><\/pre>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>make_index_sequence<\/code>:<\/p>\n<pre><code class=\"cpp\">printTupleManual(tp, std::make_index_sequence&lt;3>{});<\/code><\/pre>\n<p>\u0418 \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0440\u0442\u0435\u0436\u0430:<\/p>\n<pre><code class=\"cpp\">printTupleManual(tp, std::make_index_sequence&lt;std::tuple_size&lt;decltype(tp)>::value>{});<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u2014 <code>tuple_size_v<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0440\u043e\u0447\u0435:<\/p>\n<pre><code class=\"cpp\">printTupleManual(tp, std::make_index_sequence&lt;std::tuple_size_v&lt;decltype(tp)>>{});<\/code><\/pre>\n<p>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">template &lt;typename T> void printElem(const T&amp; x) {     std::cout &lt;&lt; x &lt;&lt; ','; };  template &lt;typename TupleT, std::size_t... Is> void printTupleManual(const TupleT&amp; tp, std::index_sequence&lt;Is...>) {     (printElem(std::get&lt;Is>(tp)), ...); }  template &lt;typename TupleT, std::size_t TupSize = std::tuple_size_v&lt;TupleT>> void printTupleGetSize(const TupleT&amp; tp) {     printTupleManual(tp, std::make_index_sequence&lt;TupSize>{}); }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0435 \u0432\u044b\u0437\u043e\u0432 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0447\u0435\u043d\u044c \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, \"hello\"}; printTupleGetSize(tp);<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/rEM8esWzn\"><u>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u043e\u0434 \u0432 @Compiler Explorer<\/u><\/a><\/p>\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u201c\u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044b\u0439\u201d \u043a\u043e\u0434 \u0432 C++ Insights, \u043f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u043e <a href=\"https:\/\/cppinsights.io\/s\/423db0e1\">\u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430\u0448 \u0432\u044b\u0437\u043e\u0432 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432:<\/p>\n<pre><code class=\"cpp\">void printTupleGetSize&lt;std::tuple&lt;int, int, const char *>, 3>      (const std::tuple&lt;int, int, const char *> &amp; tp) {   printTupleManual(tp, std::integer_sequence&lt;unsigned long, 0, 1, 2>{}); }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, <code>make_index_sequence<\/code> \u0431\u044b\u043b \u044d\u043b\u0435\u0433\u0435\u043d\u0442\u043d\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442 \u0432 <code>std::integer_sequence&lt;unsigned long, 0, 1, 2>{}<\/code>.<\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434 std::tuple \u00a0<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u043a\u043e\u0440\u0442\u0435\u0436\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0445 \u0432 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.<\/p>\n<pre><code class=\"cpp\">template &lt;typename TupleT, std::size_t... Is> void printTupleImp(const TupleT&amp; tp, std::index_sequence&lt;Is...>) {     size_t index = 0;     auto printElem = [&amp;index](const auto&amp; x) {         if (index++ > 0)              std::cout &lt;&lt; \", \";         std::cout &lt;&lt; x;     };      std::cout &lt;&lt; \"(\";     (printElem(std::get&lt;Is>(tp)), ...);     std::cout &lt;&lt; \")\"; }  template &lt;typename TupleT, std::size_t TupSize = std::tuple_size_v&lt;TupleT>> void printTuple(const TupleT&amp; tp) {     printTupleImp(tp, std::make_index_sequence&lt;TupSize>{}); }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0432\u043d\u0443\u0442\u0440\u0438 <code>printTupleImp<\/code> \u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043b <code>printElem<\/code> \u0432 \u043b\u044f\u043c\u0431\u0434\u0443. \u042d\u0442\u043e\u0442 \u0448\u0430\u0433 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043d\u0435 \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c. \u041c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0434\u043e\u043b\u0436\u0435\u043d \u043b\u0438 \u044f \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0435:<\/p>\n<pre><code class=\"cpp\">std::tuple tp { 10, 20, \"hello\"}; printTuple(tp);<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/K6KdYG6zK\"><u>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 @Compiler Explorer<\/u><\/a><\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e!<\/p>\n<p>\u041d\u043e\u2026 \u043a\u0430\u043a \u043d\u0430\u0441\u0447\u0435\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0435 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>&lt;&lt;<\/code> ? \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0435\u0441\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 <code>std::cout<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u0441\u043b\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u0440\u0442\u0435\u0436 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<h3>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 &lt;&lt; \u00a0\u00a0\u00a0\u00a0<\/h3>\n<p>\u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>ostream<\/code> :<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;ostream> #include &lt;tuple>  template &lt;typename TupleT, std::size_t... Is> std::ostream&amp; printTupleImp(std::ostream&amp; os, const TupleT&amp; tp, std::index_sequence&lt;Is...>) {     size_t index = 0;     auto printElem = [&amp;index, &amp;os](const auto&amp; x) {         if (index++ > 0)              os &lt;&lt; \", \";         os &lt;&lt; x;     };      os &lt;&lt; \"(\";     (printElem(std::get&lt;Is>(tp)), ...);     os &lt;&lt; \")\";     return os; }  template &lt;typename TupleT, std::size_t TupSize = std::tuple_size&lt;TupleT>::value> std::ostream&amp; operator &lt;&lt;(std::ostream&amp; os, const TupleT&amp; tp) {     return printTupleImp(os, tp, std::make_index_sequence&lt;TupSize>{});  }  int main() {     std::tuple tp { 10, 20, \"hello\"};     std::cout &lt;&lt; tp &lt;&lt; '\\n'; }<\/code><\/pre>\n<p><a href=\"https:\/\/godbolt.org\/z\/jn8scavWf\"><u>\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 @Compiler Explorer<\/u><\/a><\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u00a0\u00a0\u00a0<\/h3>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0430\u043c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e?<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream> #include &lt;ostream> #include &lt;tuple>  template &lt;t<\/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-330687","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330687","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=330687"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330687\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=330687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=330687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=330687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}