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
+51-1Lines changed: 51 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,56 @@ The usual `#!cpp // line comments` and `#!cpp /* stream comments */` are support
55
55
```
56
56
57
57
58
+
## <aid="lists"></a> Lists and commas
59
+
60
+
All lists use `,` commas between list items, and may be enclosed by
61
+
62
+
-`(``)` parentheses, for most lists
63
+
64
+
-`[``]` brackets, for calling the subscript operator
65
+
66
+
-`<``>` angle brackets, for template parameter/argument lists
67
+
68
+
For example:
69
+
70
+
```cpp title="Lists, using optional trailing commas just because we can" hl_lines="1 4 6 7"
71
+
print: <T,U> (t: T, u: U) = std::cout << t << u << "\n";
72
+
73
+
main: () = {
74
+
array: std::array = ('A', 'B', 'C');
75
+
76
+
for (0, 1, 2) do (e) {
77
+
print( e, array[e] );
78
+
}
79
+
// Prints:
80
+
// 0A
81
+
// 1B
82
+
// 2C
83
+
}
84
+
```
85
+
86
+
87
+
An extra comma at the end of the list, before the closing `)` or `>`, is always allowed but ignored if present (for details, see [Design note: Commas](https://github.com/hsutter/cppfront/wiki/Design-note%3A-Commas)).
88
+
89
+
For example:
90
+
91
+
```cpp title="Lists, using optional trailing commas just because we can" hl_lines="1 4 6 7"
92
+
print: <T,U,> (t: T, u: U,) = std::cout << t << u << "\n";
93
+
94
+
main: () = {
95
+
array: std::array = ('A', 'B', 'C',);
96
+
97
+
for (0, 1, 2,) do (e) {
98
+
print( e, array[e,], );
99
+
}
100
+
// Prints:
101
+
// 0A
102
+
// 1B
103
+
// 2C
104
+
}
105
+
```
106
+
107
+
58
108
## <aid="keywords"></a> Reserved keywords
59
109
60
110
Cpp2 has very few globally reserved keywords; nearly all keywords are contextual, where they have their special meaning when they appear in a particular place in the grammar. For example:
@@ -110,7 +160,7 @@ p: const * * const i32;
110
160
111
161
Cpp2 supports the same `#!cpp 'c'`haracter, `#!cpp "string"`, binary, integer, and floating point literals as Cpp1, including most Unicode encoding prefixes and raw string literals.
112
162
113
-
Cpp2 supports using Cpp1 user-defined literals for compatibility, to support seamlessly using existing libraries. However, because Cpp2 has unified function call syntax (UFCS), the preferred way to author the equivalent in Cpp2 is to just write a function or type name as a `.` call suffix. For example:
163
+
Cpp2 supports using Cpp1 user-defined literals for compatibility, to support seamlessly using existing libraries. However, because Cpp2 has [unified function call syntax (UFCS)](expressions.md#ufcs), the preferred way to author the equivalent in Cpp2 is to just write a function or type name as a `.` call suffix. For example:
114
164
115
165
- You can create a `u8` value by writing either `u8(123)` or **`123.u8()`**. [^u8using]
A template parameter list is enclosed by `<``>` angle brackets, and the parameters separated by commas. Each parameter is declared using the [same syntax as any type or object](declarations.md). If a parameter's **`:`*****kind*** is not specified, the default is `: type`.
88
+
A template parameter list is a [list](common.md#lists)enclosed by `<``>` angle brackets, and the parameters separated by commas. Each parameter is declared using the [same syntax as any type or object](declarations.md). If a parameter's **`:`*****kind*** is not specified, the default is `: type`.
Copy file name to clipboardExpand all lines: docs/cpp2/expressions.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,8 @@
3
3
4
4
## <aid="ufcs"></a> Calling functions: `f(x)` syntax, and `x.f()` UFCS syntax
5
5
6
+
A function argument list is a [list](common.md#lists) of arguments enclosed by `(``)` parentheses.
7
+
6
8
A function call like `f(x)` is a normal function call that will call non-member functions only, as usual in C++.
7
9
8
10
A function call like `x.f()` is a unified function call syntax (aka UFCS) call. It will call a member function if one is available, and otherwise will call `f(x)`. Having UFCS is important for generic code that may want to call a member or a non-member function, whichever is available. It's also important to enable fluid programming styles and natural IDE autocompletion support.
Copy file name to clipboardExpand all lines: docs/cpp2/functions.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ func: ( /* no parameters */ ) = { /* empty body */ }
14
14
15
15
## <a id="parameters"></a> Parameters
16
16
17
-
The parameter list is enclosed by `(` `)` parentheses and the parameters are separated by commas. Each parameter is declared using the [same unified syntax](declarations.md) as used for all declarations. For example:
17
+
The parameter list is a [list](common.md#lists) enclosed by `(` `)` parentheses. Each parameter is declared using the [same unified syntax](declarations.md) as used for all declarations. For example:
0 commit comments