{"id":3514,"date":"2018-06-02T10:29:43","date_gmt":"2018-06-02T09:29:43","guid":{"rendered":"http:\/\/roboblog.fatal-fury.de\/?p=3514"},"modified":"2022-02-16T11:23:09","modified_gmt":"2022-02-16T10:23:09","slug":"c-guns-print-stdarray-with-stdapply-and-fold","status":"publish","type":"post","link":"http:\/\/roboblog.fatal-fury.de\/?p=3514","title":{"rendered":"C++ Guns: print std::array or std::tuple with std::apply and fold"},"content":{"rendered":"<p><a href=\"http:\/\/roboblog.fatal-fury.de\/?p=3474\">Part 1: print std::array with std:integer_sequence<\/a><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=3508\">Part 2: convert tuple to parameter pack<\/a><br \/>\n<strong>Part 3: print std::array or std::tuple with std::apply and fold<\/strong><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=3529\">Part 4: fold over std::tuple und erzeugten Assembler Code<\/a><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=3538\">Part 5: fold over std::tuple of std::vector of Types ...<\/a><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=3617\">Part 6: apply generic lambda to tuple<\/a><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=4994\">Part 7: Play with std::tuple and std::apply<\/a><\/p>\n<p>Da ein std::array eigentlich auch nur so etwas wie ein tuple ist, nur nicht mit unterschiedlichen Typen, kann die ganze parameter pack und fold Sache auch auf std::array angewandt werden.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\ntemplate&lt;typename T, size_t N&gt;\r\nstd::ostream&amp; operator&lt;&lt;(std::ostream&amp; s, const std::array&lt;T,N&gt;&amp; arr) {\r\n    std::apply(&#x5B;&amp;](const auto&amp;...v){ (s &lt;&lt; ... &lt;&lt; v);  }, arr); \r\n    return s;\r\n}\r\n \r\nvoid func(const std::array&lt;double,2&gt;&amp; arr) {\r\n    std::cout &lt;&lt; arr;\r\n}\r\n<\/pre>\n<p>Ja, eigentlich ganz h\u00fcbsch. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Part 1: print std::array with std:integer_sequence Part 2: convert tuple to parameter pack Part 3: print std::array or std::tuple with std::apply and fold Part 4: fold over std::tuple und erzeugten Assembler Code Part 5: fold over std::tuple of std::vector of Types ... Part 6: apply generic lambda to tuple Part 7: Play with std::tuple and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[17],"class_list":["post-3514","post","type-post","status-publish","format-standard","hentry","category-allgemein","tag-cpp"],"_links":{"self":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/3514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3514"}],"version-history":[{"count":7,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/3514\/revisions"}],"predecessor-version":[{"id":4998,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/3514\/revisions\/4998"}],"wp:attachment":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3514"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}