Skip to content

Commit d3b6575

Browse files
committed
Expand comparisons section
Also add short anchor names to all subsections that don't already have them And make anchor names all lowercase-like-this
1 parent 79252d4 commit d3b6575

12 files changed

+107
-75
lines changed

Diff for: docs/cpp2/aliases.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Aliases
22

3-
## Namespace aliases
3+
## <a id="namespace-aliases"></a> Namespace aliases
44

55
TODO
66

7-
## Type aliases
7+
## <a id="type-aliases"></a> Type aliases
88

99
TODO
1010

11-
## Function aliases
11+
## <a id="function-aliases"></a> Function aliases
1212

1313
TODO
1414

15-
## Object aliases
15+
## <a id="object-aliases"></a> Object aliases
1616

1717
TODO
1818

Diff for: docs/cpp2/common.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Common programming concepts
22

3-
## `main`
3+
## <a id="main"></a> `main`
44

55
As always, `main` is the entry point of the program. For example:
66

@@ -39,7 +39,7 @@ main: (args) -> int
3939
- Some other type that your Cpp1 compiler(s) supports as a nonstandard extension.
4040

4141

42-
## Comments
42+
## <a id="comments"></a> Comments
4343

4444
The usual `#!cpp // line comments` and `#!cpp /* stream comments */` are supported. For example:
4545

@@ -55,7 +55,7 @@ The usual `#!cpp // line comments` and `#!cpp /* stream comments */` are support
5555
```
5656

5757

58-
## Reserved keywords
58+
## <a id="keywords"></a> Reserved keywords
5959

6060
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:
6161

@@ -68,7 +68,7 @@ Cpp2 has very few globally reserved keywords; nearly all keywords are contextual
6868
In rare cases, usually when consuming code written in other languages, you may need to write a name that is a reserved keyword. The way to do that is to prefix it with `__identifer__`, which treats it as an ordinary identifier (without the prefix).
6969

7070

71-
## Fundamental data types
71+
## <a id="fundamental-types"></a> Fundamental data types
7272

7373
Cpp2 supports the same fundamental types as today's Cpp1, but additionally provides the following aliases in namespace `cpp2`:
7474

@@ -97,7 +97,7 @@ Cpp2 supports the same fundamental types as today's Cpp1, but additionally provi
9797
| `_schar` | `#!cpp signed char` | Normally, prefer `i8` instead |
9898
| `_uchar` | `#!cpp unsigned char` | Normally, prefer `u8` instead |
9999

100-
## Type qualifiers
100+
## <a id="type-qualifiers"></a> Type qualifiers
101101

102102
Types can be qualified with `#!cpp const` and `#!cpp *`. Types are written left-to-right, so a qualifier always applies to what immediately follows it. For example, to declare a `#!cpp const` pointer to a non-`#!cpp const` pointer to a `#!cpp const i32` object, write:
103103

@@ -106,7 +106,7 @@ Types can be qualified with `#!cpp const` and `#!cpp *`. Types are written left-
106106
p: const * * const i32;
107107
```
108108

109-
## Literals
109+
## <a id="literals"></a> Literals
110110

111111
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.
112112

@@ -118,11 +118,11 @@ Cpp2 supports using Cpp1 user-defined literals for compatibility, to support sea
118118

119119
Both **`123.nm()`** and **`123.u8()`** are very similar to user-defined literal syntax, and more general.
120120

121-
## Operators
121+
## <a id="operators"></a> Operators
122122

123123
Operators have the same precedence and associativity as in Cpp1, but some unary operators that are prefix (always or sometimes) in Cpp1 are postfix (always) in Cpp2.
124124

125-
### Unary operators
125+
### <a id="unary-operators"></a> Unary operators
126126

127127
The operators `!`, `+`, and `-` are prefix, as in Cpp1. For example:
128128

@@ -178,7 +178,7 @@ Unary suffix operators must not be preceded by whitespace. When `*`, `&`, and `~
178178
For more details, see [Design note: Postfix unary operators vs binary operators](https://github.com/hsutter/cppfront/wiki/Design-note%3A-Postfix-unary-operators-vs-binary-operators).
179179

180180

181-
### Binary operators
181+
### <a id="binary-operators"></a> Binary operators
182182

183183
Binary operators are the same as in Cpp1. From highest to lowest precedence:
184184

Diff for: docs/cpp2/contracts.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
TODO
77

88

9-
## Contract groups
9+
## <a id="contract-groups"></a> Contract groups
1010

1111
TODO
1212

1313

14-
## Customizing the violation handler
14+
## <a id="violation-handlers"></a> Customizing the violation handler
1515

1616
TODO

Diff for: docs/cpp2/declarations.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Declaration syntax
22

3-
## Unified declaration syntax
3+
## Overview: Unified declaration syntax
44

55
All Cpp2 declarations are written as **"_name_ `:` _kind_ `=` _statement_"**.
66

@@ -61,10 +61,10 @@ n: namespace
6161
}
6262
```
6363

64-
> Note: `@enum` is a metafunction, which provides an easy way to opt into a group of defaults, constraints, and generated functions. For details, see [`@enum`, `@flag_enum`](metafunctions.md/#enum-flag_enum)
64+
> Note: `@enum` is a metafunction, which provides an easy way to opt into a group of defaults, constraints, and generated functions. For details, see [`@enum`, `@flag_enum`](metafunctions.md#enum-flag_enum)
6565
6666

67-
## `requires` constraints
67+
## <a id="requires"></a> `requires` constraints
6868

6969
TODO
7070

Diff for: docs/cpp2/expressions.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Common expressions
33

4-
## Calling functions: `f(x)` syntax, and `x.f()` UFCS syntax
4+
## <a id="ufcs"></a> Calling functions: `f(x)` syntax, and `x.f()` UFCS syntax
55

66
A function call like `f(x)` is a normal function call that will call non-member functions only, as usual in C++.
77

@@ -41,13 +41,13 @@ To explicitly treat an object name passed as an argument as `move` or `out`, wri
4141

4242
- Explicit `move` is rarely needed. Every definite last use of a local variable will apply `move` by default. Writing `move` from an object before its definite last use means that later uses may see a moved-from state.
4343

44-
- Explicit `out` is needed only when initializing a local variable separately from its declaration using a call to a function with an `out` parameter. For details, see [Guaranteed initialization](../cpp2/objects.md#Init).
44+
- Explicit `out` is needed only when initializing a local variable separately from its declaration using a call to a function with an `out` parameter. For details, see [Guaranteed initialization](../cpp2/objects.md#init).
4545

4646
For example:
4747

4848

4949

50-
## `_` — the "don't care" wildcard, including explicit discard
50+
## <a id="wildcard"></a> `_` — the "don't care" wildcard, including explicit discard
5151

5252
`_` is pronounced **"don't care"** and allowed as a wildcard in most contexts. For example:
5353

@@ -84,7 +84,7 @@ _ = vec.emplace_back(1,2,3);
8484
For details, see [Design note: Explicit discard](https://github.com/hsutter/cppfront/wiki/Design-note%3A-Explicit-discard). In Cpp2, data is always initialized, data is never silently lost, data flow is always visible. Data is precious, and it's always safe.
8585

8686

87-
## `is` — safe type/value queries
87+
## <a id="is"></a> `is` — safe type/value queries
8888

8989
An `x is C` expression allows safe type and value queries, and evaluates to `#!cpp true` if `x` matches constraint `C`. It supports both static and dynamic queries, including customization, with support for standard library dynamic types like `std::variant`, `std::optional`, `std::expected`, and `std::any` provided out of the box.
9090

@@ -132,7 +132,7 @@ Here are some `is` queries with their Cpp1 equivalents. In this table, uppercase
132132
> Note: `is` unifies a variety of differently-named Cpp1 language and library queries under one syntax, and supports only the type-safe ones.
133133
134134

135-
## `as` — safe casts and conversions
135+
## <a id="as"></a> `as` — safe casts and conversions
136136

137137
An `x as T` expression allows safe type casts. `x` must be an object or expression, and `T` must be a type. Like `is`, `as` supports both static and dynamic typing, including customization, with support for standard library dynamic types like `std::variant`, `std::optional`, `std::expected`, and `std::any` provided out of the box. For example:
138138

@@ -169,7 +169,7 @@ Here are some `as` casts with their Cpp1 equivalents. In this table, uppercase n
169169
> Note: `as` unifies a variety of differently-named Cpp1 language and library casts and conversions under one syntax, and supports only the type-safe ones.
170170
171171

172-
## `inspect` — pattern matching
172+
## <a id="inspect"></a> `inspect` — pattern matching
173173

174174
An `inspect expr -> Type` expression allows pattern matching using `is`.
175175

@@ -210,7 +210,7 @@ test(42);
210210
For more examples, see also the examples in the previous two sections on `is` and `as`, many of which use `inspect`.
211211
212212
213-
## `$` — captures, including interpolations
213+
## <a id="captures"></a> `$` — captures, including interpolations
214214
215215
Suffix `$` is pronounced **"paste the value"** and captures the value of an expression at the point when the expression where the capture is written is evaluated. Depending the complexity of the capture expression `expr$` and where it is used, parentheses `(expr)$` may be required for precedence or to show the boundaries of the expression.
216216
@@ -219,7 +219,7 @@ Suffix `$` is pronounced **"paste the value"** and captures the value of an expr
219219
Any capture is evaluated at the point where it is written, in the function expression, contract postcondition, or string literal. The stored captured value can then be used later when the context it is in is evaluated, such as when the function expression body it's in is actually called later (one or more times), when the postcondition it's in is evaluated later when the function returns, or when the string literal it's in is read later.
220220
221221
222-
### Capture in function expressions (aka lambdas)
222+
### <a id="function-captures"></a> Capture in function expressions (aka lambdas)
223223
224224
Any capture in a function expression body is evaluated at the point where the function expression is written, at the declaration of the function expression. The function expression itself is then evaluated each time the function is invoked, and can reference the captured value.
225225
@@ -240,7 +240,7 @@ main: () = {
240240
The design and syntax are selected so that capture is spelled the same way in all contexts. For details, see [Design note: Capture](https://github.com/hsutter/cppfront/wiki/Design-note%3A-Capture).
241241

242242

243-
### Capture in contract postconditions
243+
### <a id="postcondition-captures"></a> Capture in contract postconditions
244244

245245
Any capture in a postcondition is evaluated at the point where the postcondition is written, at the beginning (entry) of the function. The postcondition itself is then evaluated when the function returns, and can reference the captured value.
246246

@@ -256,7 +256,7 @@ push_back: (coll, value)
256256
```
257257

258258

259-
### Capture in string interpolation
259+
### <a id="interpolation"></a> Capture in string interpolation
260260

261261
A string literal can capture the value of an expression `expr` by writing `(expr)$` inside the string literal. The `(` `)` are required, and cannot be nested. A string literal has type `std::string` if it performs any captures, otherwise it is a normal C/C++ string literal (array of characters).
262262

Diff for: docs/cpp2/functions.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
TODO
77

88

9-
## Parameters
9+
## <a id="parameters"></a> Parameters
1010

1111
There are six ways to pass parameters that cover all use cases:
1212

@@ -23,12 +23,12 @@ There are six ways to pass parameters that cover all use cases:
2323
> 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).
2424
2525

26-
## Return values
26+
## <a id="return-values"></a> Return values
2727

2828
TODO
2929

3030

31-
### Function outputs
31+
### <a id="nodiscard-outputs"></a> Function outputs are not implicitly discardable
3232

3333
A function's outputs are its return values, and the "out" state of any `out` and `inout` parameters.
3434

@@ -74,13 +74,13 @@ main: ()
7474
> - A function call written in Cpp2 `x.f()` member call syntax always treats a non-`#!cpp void` return type as not discardable, even if the function was written in Cpp1 syntax that did not write `[[nodiscard]]`.
7575
7676

77-
## Control flow
77+
## <a id="control flow"></a> Control flow
7878

79-
## `#!cpp if`, `#!cpp else` — Branches
79+
## <a id="branches"></a> `#!cpp if`, `#!cpp else` — Branches
8080

8181
TODO
8282

83-
## `#!cpp for`, `#!cpp while`, `#!cpp do` — Loops
83+
## <a id="loops"></a> `#!cpp for`, `#!cpp while`, `#!cpp do` — Loops
8484

8585
TODO
8686

@@ -104,15 +104,15 @@ outer: while i<M next i++ { // loop named "outer"
104104
}
105105
```
106106

107-
## Unnamed function expressions (aka lambdas)
107+
## <a id="function-expressions"></a> Unnamed function expressions (aka lambdas)
108108

109109
TODO
110110

111-
## Move/forward from last use
111+
## <a id="definite-last-use"></a> Move/forward from definite last use
112112

113113
TODO
114114

115-
## Generality: Unifying functions and local scopes
115+
## <a id="function-scope-unification"></a> Generality: Unifying functions and local scopes
116116

117117
TODO
118118

Diff for: docs/cpp2/metafunctions.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A metafunction is a compile-time function that can participate in interpreting t
1111

1212
The most important thing about metafunctions is that they are not hardwired language features — they are compile-time library code that uses the reflection and code generation API, that lets the author of an ordinary type easily opt into a named set of defaults, requirements, and generated contents. This approach is essential to making the language simpler, because it lets us avoid hardwiring special "extra" types into the language and compiler.
1313

14-
## Applying metafunctions
14+
## <a id="applying-metafunctions"></a> Applying metafunctions
1515

1616
Metafunctions provide an easy way for a type author to opt into a group of defaults, constraints, and generated functions: Just write `@name` afer the `:` of a declaration, where `name` is the name of the metafunction. This lets the type author declare (and the human reader see) the intent up front: "This isn't just any `type`, this is a `@value type`" which automatically gives the type default/copy/move construction and assignment, `<=>` with `std::strong_ordering` comparisons, and guarantees that it has a public destructor and no protected or virtual functions:
1717

@@ -26,12 +26,12 @@ point2d: @value type = {
2626
}
2727
```
2828

29-
## Generating source code at compile time
29+
## <a id="generating-source"></a>Generating source code at compile time
3030

3131
TODO
3232

3333

34-
## Built-in metafunctions
34+
## <a id="built-in-metafunctions"></a>Built-in metafunctions
3535

3636
The following metafunctions are provided in the box with cppfront.
3737

@@ -45,7 +45,7 @@ TODO
4545
TODO
4646

4747

48-
### ordered, weakly_ordered, partially_ordered
48+
### <a id="ordered"></a>ordered, weakly_ordered, partially_ordered
4949

5050
TODO
5151

@@ -55,7 +55,7 @@ TODO
5555
TODO
5656

5757

58-
### basic_value, value, weakly_ordered_value, partially_ordered_value
58+
### <a id="value"></a>basic_value, value, weakly_ordered_value, partially_ordered_value
5959

6060
TODO
6161

@@ -65,7 +65,7 @@ TODO
6565
TODO
6666

6767

68-
### `enum`, `flag_enum`
68+
### `enum`
6969

7070
Cpp2 has no `enum` feature hardwired into the language. Instead you apply the `@enum` metafunction when writing an ordinary `type`:
7171

@@ -111,7 +111,9 @@ janus: @enum type = {
111111
}
112112
```
113113

114-
There's also a `flag_enum` variation with power-of-two semantics and an unsigned underlying type:
114+
### `flag_enum`
115+
116+
`flag_enum` is a variation on `enum` that has power-of-two default enumerator values, a default unsigned underlying type, and supports bitwise operators:
115117

116118
``` cpp title="Using the @flag_enum metafunction when writing a type" hl_lines="11"
117119
// file_attributes is declaratively a safe flag enum type:
@@ -207,12 +209,12 @@ TODO
207209
TODO
208210

209211

210-
## Writing your own metafunctions
212+
## <a id="writing-metafunctions"></a> Writing your own metafunctions
211213

212214
TODO
213215

214216

215-
## Reflection API reference
217+
## <a id="reflection-api"></a> Reflection API reference
216218

217219
TODO
218220

Diff for: docs/cpp2/objects.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Its declaration is written using the same **name `:` kind `=` value** [declarati
66

77
- **name** starts with a letter and is followed by other letters, digits, or `_`. Examples: `count`, `skat_game`, `Point2D` are valid names.
88

9-
- **kind** is the object's type. In most places, except type scopes, you can write the `_` wildcard as the type (or omit the type entirely) to ask for the type to be deduced. When the type is a template, the templated arguments can be inferred from the constructor (via [CTAD](../welcome/hello-world.md#CTAD)).
9+
- **kind** is the object's type. In most places, except type scopes, you can write the `_` wildcard as the type (or omit the type entirely) to ask for the type to be deduced. When the type is a template, the templated arguments can be inferred from the constructor (via [CTAD](../welcome/hello-world.md#ctad)).
1010

1111
- **value** is the object's initial value. To use the default-constructed value, write `()`.
1212

@@ -26,7 +26,7 @@ count := -1; // same, deducing the object's type by just omitting it
2626
```
2727

2828

29-
## <a id="Init"></a> Guaranteed initialization
29+
## <a id="init"></a> Guaranteed initialization
3030

3131
Every object must be initialized using `=` before it is used.
3232

@@ -95,7 +95,7 @@ load_from_disk: (out buffer) = {
9595
In the above example, note the simple rule for branches: The local variable must be initialized on both the `#!cpp if` and `#!cpp else` branches, or neither branch.
9696

9797

98-
## Heap objects
98+
## <a id="heap"></a>Heap objects
9999

100100
Objects can also be allocated on the heap using `#!cpp arena.new <T> (/*initializer, arguments*/)` where `arena` is any object that acts as a memory arena and provides a `#!cpp .new` function template. Two memory arena objects are provided in namespace `cpp2`:
101101

0 commit comments

Comments
 (0)