Skip to content

Commit 4385a62

Browse files
committed
Add example of parameter passing kinds
1 parent ef47ef4 commit 4385a62

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

docs/cpp2/functions.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,28 @@ func: (
2727
}
2828
```
2929

30-
There are six ways to pass parameters that cover all use cases:
30+
There are six ways to pass parameters that cover all use cases, that can be written before the parameter name:
3131

3232
| Parameter ***kind*** | "Pass me an `x` I can ______" | Accepts arguments that are | Special semantics | ***kind*** `x: X` Compiles to Cpp1 as |
3333
|---|---|---|---|---|
3434
| `in` (default) | read from | anything | always `#!cpp const`<p>automatically passes by value if cheaply copyable | `X const x` or `X const& x` |
3535
| `copy` | take a copy of | anything | acts like a normal local variable initialized with the argument | `X x` |
3636
| `inout` | read from and write to | lvalues | | `X& x` |
37-
| `out` | write to (including construct) | lvalues, including uninitialized lvalues | must `=` assign/construct before other uses | `cpp2::out<X>` |
38-
| `move` | move from | rvalues | automatically moves from every definite last use | `X&&` |
37+
| `out` | write to (including construct) | lvalues (including uninitialized) | must `=` assign/construct before other uses | `cpp2::impl::out<X>` |
38+
| `move` | move from (consume the value of) | rvalues | automatically moves from every definite last use | `X&&` |
3939
| `forward` | forward | anything | automatically forwards from every definite last use | `T&&` constrained to type `X` |
4040

41+
For example:
42+
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
47+
)
48+
= {
49+
// ...
50+
}
51+
```
4152

4253
> Note: All parameters and other objects in Cpp2 are `#!cpp const` by default, except for local variables. For details, see [Design note: `#!cpp const` objects by default](https://github.com/hsutter/cppfront/wiki/Design-note%3A-const-objects-by-default).
4354

0 commit comments

Comments
 (0)