{"id":1329,"date":"2025-03-07T10:36:39","date_gmt":"2025-03-07T10:36:39","guid":{"rendered":"https:\/\/blog.faktor0.de\/?p=1329"},"modified":"2025-03-07T11:04:08","modified_gmt":"2025-03-07T11:04:08","slug":"c-lambda-captures","status":"publish","type":"post","link":"https:\/\/blog.faktor0.de\/?p=1329","title":{"rendered":"C++ Lambda Captures"},"content":{"rendered":"<p>The difference is how the values are captured<\/p>\n<li>&#038; captures by reference<\/li>\n<li>= captures by value<\/li>\n<p>Example:<br \/>\n<code><br \/>\nint x = 1;<br \/>\nauto valueLambda = [=]() { cout << x << endl; };<br \/>\nauto refLambda = [&]() { cout << x << endl; };<br \/>\nx = 13;<br \/>\nvalueLambda();<br \/>\nrefLambda();<br \/>\n<\/code><\/p>\n<p>This code will print:<br \/>\n<code><br \/>\n<strong>1<\/strong><br \/>\n<strong>13<\/strong><br \/>\n<\/code><\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/21105169\/is-there-any-difference-betwen-and-in-lambda-functions\">https:\/\/stackoverflow.com\/questions\/21105169\/is-there-any-difference-betwen-and-in-lambda-functions<\/a><br \/>\n<a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/lambda\">https:\/\/en.cppreference.com\/w\/cpp\/language\/lambda<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The difference is how the values are captured &#038; captures by reference = captures by value Example: int x = 1; auto valueLambda = [=]() { cout<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3],"tags":[],"class_list":["post-1329","post","type-post","status-publish","format-standard","hentry","category-c","category-programmieren"],"_links":{"self":[{"href":"https:\/\/blog.faktor0.de\/index.php?rest_route=\/wp\/v2\/posts\/1329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.faktor0.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.faktor0.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.faktor0.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.faktor0.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1329"}],"version-history":[{"count":9,"href":"https:\/\/blog.faktor0.de\/index.php?rest_route=\/wp\/v2\/posts\/1329\/revisions"}],"predecessor-version":[{"id":1338,"href":"https:\/\/blog.faktor0.de\/index.php?rest_route=\/wp\/v2\/posts\/1329\/revisions\/1338"}],"wp:attachment":[{"href":"https:\/\/blog.faktor0.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.faktor0.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.faktor0.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}