You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cpp2/common.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,7 +202,7 @@ The operators `.`, `..`, `*`, `&`, `~`, `++`, `--`, `()`, `[]`, `...`, `..=`, an
202
202
203
203
Postfix notation lets the code read fluidly left-to-right, in the same order in which the operators will be applied, and lets declaration syntax be consistent with usage syntax. For more details, see [Design note: Postfix operators](https://github.com/hsutter/cppfront/wiki/Design-note%3A-Postfix-operators).
204
204
205
-
> Note: The function call syntax `f(x)` calls a namespace-scope function, or a function object, named `f`. The function call syntax `x.f()` is a unified function call syntax (aka UFCS) that calls a type-scope function in the type of `x` if available, otherwise calls the same as `f(x)`. The function call syntax `x..f()` calls a type-scope function only. For details, see [Design note: UFCS](https://github.com/hsutter/cppfront/wiki/Design-note%3A-UFCS).
205
+
> Note: The function call syntax `f(x)` calls a namespace-scope function only. The function call syntax `x.f()` is a unified function call syntax (aka UFCS) that calls a type-scope function in the type of `x` if available, otherwise calls the same as `f(x)`. The function call syntax `x..f()` calls a type-scope function only. For details, see [Design note: UFCS](https://github.com/hsutter/cppfront/wiki/Design-note%3A-UFCS).
206
206
207
207
| Unary operator | Cpp2 example | Cpp1 equivalent |
208
208
|---|---|---|
@@ -214,9 +214,9 @@ Postfix notation lets the code read fluidly left-to-right, in the same order in
214
214
|`#!cpp --`|`#!cpp iter--`|`#!cpp --iter`|
215
215
|`(``)`|`#!cpp f( 1, 2, 3)`|`#!cpp f( 1, 2, 3)`|
216
216
|`[``]`|`#!cpp vec[123]`|`#!cpp vec[123]`|
217
-
|`...`(half-open range operator) |`#!cpp v.begin()...v.end()`|`#!cpp std::ranges::subrange(v.begin(), v.end())`|
218
-
|`..=`(closed range operator) |`#!cpp 1..=10`|`#!cpp std::views::iota(1, 11)`|
219
-
|`$`(capture operator) |`val$`|_reflection — no Cpp1 equivalent yet_|
Copy file name to clipboardExpand all lines: docs/cpp2/functions.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,17 @@ func: (
27
27
}
28
28
```
29
29
30
+
The parameter type can be deduced by writing `_` (the default, so it can be omitted). You can use `is` to declare a type constraint (e.g., a concept) that a deduced type must match, in which case `_` is required. For example:
31
+
32
+
```cpp title="Declaring a parameter of constrained deduced type" hl_lines="2 3 6"
33
+
// ordinary generic function, x's type is deduced
34
+
print: (x: _) = { std::cout << x; }
35
+
print: (x) = { std::cout << x; } // same, using the _ default
36
+
37
+
// number's type is deduced, but must match the std::integral concept
38
+
calc: (number: _ is std::integral) = { /*...*/ }
39
+
```
40
+
30
41
There are six ways to pass parameters that cover all use cases, that can be written before the parameter name:
31
42
32
43
| Parameter ***kind*** | "Pass me an `x` I can ______" | Accepts arguments that are | Special semantics | ***kind*** `x: X` Compiles to Cpp1 as |
Copy file name to clipboardExpand all lines: docs/cpp2/objects.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,13 @@ pi: <T: type> T == 3.14159'26535'89793'23846L;
29
29
pi: _ == 3.14159'26535'89793'23846L; // same, deducing the object's type
30
30
```
31
31
32
+
The parameter type can be deduced by writing `_` (the default, so it can be omitted). You can use `is` to declare a type constraint (e.g., a concept) that a deduced type must match, in which case `_` is required. For example:
33
+
34
+
```cpp title="Declaring an object of constrained deduced type" hl_lines="2"
35
+
// number's type is deduced, but must match the std::regular concept
36
+
number: _ is std::regular = some_factory_function();
0 commit comments