Skip to content

Commit b4762a8

Browse files
committed
Clarify forward parameter and return docs
Also remove stray material in the parameters section that's covered in the returns section
1 parent 2c03e41 commit b4762a8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/cpp2/functions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ There are six ways to pass parameters that cover all use cases, that can be writ
6666
| <big>**`inout`**</big> | can read from and write to | lvalues | | `X& x` |
6767
| <big>**`out`**</big> | writes to (including construct) | lvalues (including uninitialized) | must `=` assign/construct before other uses | `cpp2::impl::out<X>` |
6868
| <big>**`move`**</big> | moves from (consume the value of) | rvalues | automatically moves from every definite last use | `X&&` |
69-
| <big>**`forward`**</big> | forwards | anything | automatically forwards from every definite last use<br><br> for a deduced type (`-> forward _`), deduces a by-reference or by-value return (the latter if the function returns an rvalue); to guarantee a by-reference return, use `-> forward_ref _` | for&nbsp;a&nbsp;specific&nbsp;type, `-> forward T` compiles to Cpp1 `-> T&&`, and adds `const` if the function has an `in this` parameter (Cpp1 `const` member function)<br><br> for a deduced type, `-> forward _` compiles to Cpp1 `-> decltype(auto)`, and `-> forward_ref _` compiles to Cpp1 `-> auto&&` |
69+
| <big>**`forward`**</big> | forwards | anything | automatically forwards from every definite last use | `auto&&`, and if a specific type is named also a `requires`-constraint requiring convertibilty to that type |
7070
7171
> 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).
7272
@@ -102,7 +102,7 @@ A function can return either a single anonymous return value, or a return parame
102102
To deduce the return type, write `_`:
103103

104104
- `-> _` deduces by-value return.
105-
- `-> forward _` deduces by-value return (if the function returns an rvalue) or by-reference return (everything else).
105+
- `-> forward _` deduces by-value return (if the function returns a prvalue or type member object) or by-reference return (everything else), based on the `decltype` of the returned expression.
106106
- `-> forward_ref _` deduces by-reference return only.
107107

108108
A function whose body is a single expression `= expr;` defaults to `-> forward _ = { return expr; }`.

0 commit comments

Comments
 (0)