{"id":4332,"date":"2021-11-03T22:02:47","date_gmt":"2021-11-03T14:02:47","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=4332"},"modified":"2021-11-04T09:54:00","modified_gmt":"2021-11-04T01:54:00","slug":"c14-generalized-capture-lambda","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=4332","title":{"rendered":"c++14 new feature"},"content":{"rendered":"\n<p>1\u3001 lambda\u8868\u8fbe\u5f0f\u5e7f\u4e49\u6355\u83b7(generalized capture)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int apple = 100;\nint dog = 200;\nauto ap1 = [dog1=dog, apple1=apple] \n{\n    printf(\"%d\\n\", apple1);\n};\nauto ap2 = [apple2 = &amp;apple]\n{\n    printf(\"%d\\n\", *apple2);\n};\napple++;\nap1();\nap2();<\/code><\/pre>\n\n\n\n<p>2\u3001\u8fd4\u56de\u7c7b\u578b\u81ea\u52a8\u63a8\u5bfc<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>auto add = [](auto x, auto y) \n{ \n    return x + y; \n};\n\nvoid Chapter5()\n{\n    auto m = add(10L, 20L);\n    auto s = add(std::string(\"a\"), std::string(\"b\"));\n    printf(\"%d,%s\\n\", m, s.c_str());\n}<\/code><\/pre>\n\n\n\n<p>3\u3001\u4e8c\u8fdb\u5236\u8868\u8fbe\u5f0f\u7684\u5b57\u9762\u91cf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>constexpr int val = 0b101;\nprintf(\"%d\\n\", val);<\/code><\/pre>\n\n\n\n<p>4\u3001\u5b57\u7b26\u4e32\u8868\u8fbe\u5f0f\u7684\u5b57\u9762\u91cf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>std::string s = R\"( c:\\program\\\u4e2d\\ )\";\n\u4f7f\u7528 R\"(  \u548c  )\";<\/code><\/pre>\n\n\n\n<p>5\u3001for\u5faa\u73af<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int arr[] = {1,2,3,4};\nfor(auto i: arr)\n{\n}<\/code><\/pre>\n\n\n\n<p>6\u3001<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001 lambda\u8868\u8fbe\u5f0f\u5e7f\u4e49\u6355\u83b7(generalized capture) 2\u3001\u8fd4\u56de\u7c7b\u578b\u81ea\u52a8\u63a8\u5bfc 3\u3001\u4e8c\u8fdb\u5236\u8868 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/4332"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4332"}],"version-history":[{"count":6,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/4332\/revisions"}],"predecessor-version":[{"id":4338,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/4332\/revisions\/4338"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}