{"id":19162,"date":"2025-09-05T08:19:54","date_gmt":"2025-09-05T08:19:54","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=19162"},"modified":"2025-09-05T11:37:14","modified_gmt":"2025-09-05T11:37:14","slug":"variadic-templates-with-fold-expressions","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=19162","title":{"rendered":"Variadic templates with fold expressions"},"content":{"rendered":"<pre class=\"brush: cpp; gutter: false; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n\r\ntemplate&lt;typename... Args&gt;\r\nauto sum_all(Args... args) {\r\n    return (args + ...);\r\n}\r\n\r\ntemplate&lt;typename... Args&gt;\r\nauto any_true(Args... args) {\r\n    return (args || ...);\r\n}\r\n\r\ntemplate&lt;typename... Args&gt;\r\nvoid print_all(Args... args) {\r\n    ((std::cout &lt;&lt; args &lt;&lt; &quot; &quot;), ...);\r\n    std::cout &lt;&lt; &quot;\\n&quot;;\r\n}\r\n\r\nint main() {\r\n    auto sum = sum_all(1, 2, 3, 4, 5);\r\n    auto res = any_true(false, true, false);\r\n    print_all(&quot;Hello&quot;, 42, 3.14, &#039;A&#039;);\r\n    return 0;\r\n}\r\n<\/pre>\n<p><strong>Details<\/strong><br \/>\n&#8211; The compiler expands the fold at compile time into a normal expression.<br \/>\n&#8211; The precalculation depends on whether the arguments are known at compile time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Details &#8211; The compiler expands the fold at compile time into a normal expression. &#8211; The precalculation depends on whether<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[27],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/19162"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19162"}],"version-history":[{"count":12,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/19162\/revisions"}],"predecessor-version":[{"id":19174,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/19162\/revisions\/19174"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19162"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}