mirror of
https://github.com/changkun/modern-cpp-tutorial.git
synced 2025-12-17 04:34:40 +03:00
@@ -105,6 +105,8 @@ The type of the captured variable being declared is judged according to the expr
|
|||||||
and the judgment is the same as using `auto`:
|
and the judgment is the same as using `auto`:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
void lambda_expression_capture() {
|
void lambda_expression_capture() {
|
||||||
auto important = std::make_unique<int>(1);
|
auto important = std::make_unique<int>(1);
|
||||||
auto add = [v1 = 1, v2 = std::move(important)](int x, int y) -> int {
|
auto add = [v1 = 1, v2 = std::move(important)](int x, int y) -> int {
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ C++14 给与了我们方便,允许捕获的成员用任意的表达式进行
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <utility>
|
#include <memory> // std::make_unique
|
||||||
|
#include <utility> // std::move
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
auto important = std::make_unique<int>(1);
|
auto important = std::make_unique<int>(1);
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <utility>
|
#include <memory> // std::make_unique
|
||||||
|
#include <utility> // std::move
|
||||||
|
|
||||||
void lambda_value_capture() {
|
void lambda_value_capture() {
|
||||||
int value = 1;
|
int value = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user