| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,17 +27,28 @@ func: ( | |||
| 27 | 27 | } | |
| 28 | 28 | ``` | |
| 29 | 29 | ||
| 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: | ||
| 31 | 31 | ||
| 32 | 32 | | Parameter ***kind*** | "Pass me an `x` I can ______" | Accepts arguments that are | Special semantics | ***kind*** `x: X` Compiles to Cpp1 as | | |
| 33 | 33 | |---|---|---|---|---| | |
| 34 | 34 | | `in` (default) | read from | anything | always `#!cpp const`<p>automatically passes by value if cheaply copyable | `X const x` or `X const& x` | | |
| 35 | 35 | | `copy` | take a copy of | anything | acts like a normal local variable initialized with the argument | `X x` | | |
| 36 | 36 | | `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&&` | | ||
| 39 | 39 | | `forward` | forward | anything | automatically forwards from every definite last use | `T&&` constrained to type `X` | | |
| 40 | 40 | ||
| 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 | + ``` | ||
| 41 | 52 | ||
| 42 | 53 | > 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). | |
| 43 | 54 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments