Skip to content

Commit 581c8c1

Browse files
committed
Add old example
1 parent 13471fa commit 581c8c1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

sources/modules/functions/lambdas.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ std::ranges::for_each(
161161
});
162162
```
163163

164+
In a context where only one expression is allowed, like `assert`, one can use an immediately lambda to write multiple statements.
165+
```
166+
assert([](){
167+
std::vector v{1, 2, 3, 4, 5};
168+
for (auto x: v) std::cout << v << std::endl;
169+
}());
170+
```
171+
164172
When to use lambdas or not:
165173
forcing code into a lambda can prevent some features
166174
```

0 commit comments

Comments
 (0)