MCPcopy Create free account
hub / github.com/changkun/modern-cpp-tutorial / learn_lambda_func_1

Function learn_lambda_func_1

code/3/3.1.cpp:12–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include <utility>
11
12void learn_lambda_func_1() {
13 int value_1 = 1;
14 auto copy_value_1 = [value_1] {
15 return value_1;
16 };
17 value_1 = 100;
18 auto stored_value_1 = copy_value_1();
19 // 这时, stored_value_1 == 1, 而 value_1 == 100.
20 // 因为 copy_value_1 在创建时就保存了一份 value_1 的拷贝
21}
22
23void learn_lambda_func_2() {
24 int value_2 = 1;

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected