From a548ea79bd51b338f245e00c3ef8359be8bc4e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=96=E7=A0=81=E7=BF=81?= Date: Sat, 23 Jun 2018 03:24:10 -0400 Subject: [PATCH] Print out the stored_value1 and stored_value2 for the lambda example. (#36) * Fix compilation error for structured binding The header is missing. After adding it, it compiles fine with clang in c++17 mode. * Print out the stored_value1 and stored_value2 for the lambda example. To make it eaiser for the readers to understand the difference between lambda capture by value and by reference. --- code/3/3.1.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/3/3.1.cpp b/code/3/3.1.cpp index e179fdd..71b4e3e 100644 --- a/code/3/3.1.cpp +++ b/code/3/3.1.cpp @@ -16,6 +16,7 @@ void learn_lambda_func_1() { }; value_1 = 100; auto stored_value_1 = copy_value_1(); + std::cout << "stored_value_1=" << stored_value_1 << std::endl; // 这时, stored_value_1 == 1, 而 value_1 == 100. // 因为 copy_value_1 在创建时就保存了一份 value_1 的拷贝 } @@ -27,6 +28,7 @@ void learn_lambda_func_2() { }; value_2 = 100; auto stored_value_2 = copy_value_2(); + std::cout << "stored_value_2=" << stored_value_2 << std::endl; // 这时, stored_value_2 == 100, value_1 == 100. // 因为 copy_value_2 保存的是引用 }