You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -466,32 +466,32 @@ Next, `in` is the default [parameter kind](#parameters). So we can use that defa
466
466
equals: (a, b) -> _ = { return a == b; }
467
467
```
468
468
469
-
We already saw that `{` `}` is the default for a single-line function that returns nothing. Similarly, `{ return` and `}` is the default for a single-line function that returns something:
469
+
We already saw that `{ return` ... `; }` is the default for a single-expression function body that deduces its return type:
470
470
471
471
``` cpp title="equals: Identical meaning, now using the { return ... } default body decoration"
472
472
equals: (a, b) -> _ = a == b;
473
473
```
474
474
475
-
Next, `#!cpp -> _ =` (deduced return type) is the default for single-expression functions that return something and so can be omitted:
475
+
Next, `#!cpp -> forward _` (fully deduced return type) is the default for single-expression functions that return something, and in this case will have the same meaning as `#!cpp -> _`:
476
476
477
477
```cpp title="equals: Identical meaning, now using the -> _ = default for functions that return something"
478
-
equals: (a, b) a == b;
478
+
equals: (a, b) = a == b;
479
479
```
480
480
481
481
Finally, at expression scope (aka "lambda/temporary") functions/objects aren't named, and the trailing `;` is optional:
482
482
483
483
```cpp title="(not) 'equals': Identical meaning, but without a name as an unnamed function at expression scope"
484
-
:(a, b) a == b
484
+
:(a, b) = a == b
485
485
```
486
486
487
487
Here are some additional examples of unnamed function expressions:
488
488
489
489
```cpp title="Some more examples of unnamed function expressions"
490
490
std::ranges::for_each( a, :(x) = std::cout << x );
491
491
492
-
std::ranges::transform( a, b, :(x) x+1 );
492
+
std::ranges::transform( a, std::back_inserter(b), :(x) = x+1 );
493
493
494
-
where_is = std::ranges::find_if( a, :(x) x == waldo$ );
494
+
where_is = std::ranges::find_if( b, :(x) = x == waldo$ );
495
495
```
496
496
497
497
> Note: Cpp2 doesn't have a separate "lambda" syntax; you just use the regular function syntax at expression scope to write an unnamed function, and the syntactic defaults are chosen to make such function expressions convenient to write. And because in Cpp2 every local variable [capture](expressions.md#captures) (for example, `waldo$` above) is written in the body, it doesn't affect the function syntax.
Copy file name to clipboardExpand all lines: docs/cpp2/types.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -281,6 +281,8 @@ The above is the same as in Cpp1 because most of Cpp2's `#!cpp operator<=>` feat
281
281
if lo <= requested < hi {
282
282
// ... do something ...
283
283
}
284
+
285
+
// Equivalent result to: (lo ..< hi).contains( requested )
284
286
```
285
287
286
288
For more details, see [P0515R0 "Consistent comparison" section 3.3](https://wg21.link/p0515r0) and [P0893 "Chaining comparisons"](https://wg21.link/p0893).
0 commit comments