Skip to content

Commit ddcf0fd

Browse files
committed
Add note that a single named return value is lowered like an unnamed one
Per #1119 comment thread
1 parent fc27684 commit ddcf0fd

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

docs/cpp2/functions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ add: <T: type, U: type> (a:T, b:U) -> decltype(a+b) = { return a+b; }
8484
add: (a, b) -> _ = a+b;
8585
```
8686
87-
(2) **`#!cpp -> ( /* parameter list */ )`** to return a list of named return parameters using the same [parameters](#parameters) syntax, but where the only passing styles are `out` (the default, which moves where possible) or `forward`. The function body must [initialize](objects.md#init) the value of each return-parameter `ret` in its body the same way as any other local variable. An explicit return statement is written just `#!cpp return;` and returns the named values; the function has an implicit `#!cpp return;` at the end. For example:
87+
(2) **`#!cpp -> ( /* parameter list */ )`** to return a list of named return parameters using the same [parameters](#parameters) syntax, but where the only passing styles are `out` (the default, which moves where possible) or `forward`. The function body must [initialize](objects.md#init) the value of each return-parameter `ret` in its body the same way as any other local variable. An explicit return statement is written just `#!cpp return;` and returns the named values; the function has an implicit `#!cpp return;` at the end. If only a single return parameter is in the list, it is emitted in the lowered Cpp1 code the same way as (1) above, so its name is only available inside the function body.
88+
89+
For example:
8890
8991
``` cpp title="Function with multiple/named return values" hl_lines="1 3-4 7-8 14 16-17"
9092
divide: (dividend: int, divisor: int) -> (quotient: int, remainder: int) = {

0 commit comments

Comments
 (0)