Skip to content

Commit 2722478

Browse files
committed
Improve parameter passing examples a bit
1 parent 4385a62 commit 2722478

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Diff for: docs/cpp2/functions.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,21 @@ There are six ways to pass parameters that cover all use cases, that can be writ
4040

4141
For example:
4242

43-
``` cpp title="Declaring parameters" hl_lines="2 3"
44-
func: (
45-
x : i32, // ('in' is default) x is const within func
46-
inout y : std::string // y is modifiable
43+
``` cpp title="Declaring parameter kinds" hl_lines="2 3 10"
44+
append_x_to_y: (
45+
x : i32, // an i32 I can read from (i.e., const)
46+
inout y : std::string // a string I can read from and write to
4747
)
4848
= {
49-
// ...
49+
y = y + to_string(x); // read x, read and write y
50+
}
51+
52+
wrap_f: (
53+
forward x // a generic value of deduced type I can forward
54+
) // (omitting x's type means the same as ': _')
55+
= {
56+
global_counter += x; // ok to read x
57+
f(x); // last use: automatically does 'std::forward<T>(x)'
5058
}
5159
```
5260

0 commit comments

Comments
 (0)