Skip to content

docs: fix some typos and confusing wording #976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/reference-cpp2.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### Comments

The usual `// line comments` and `/* stream comments */` are supported. For exmaple:
The usual `// line comments` and `/* stream comments */` are supported. For example:

``` cpp title="Example: Comments"
// A line comment: After //, the entire rest of the line is part of the comment
Expand Down Expand Up @@ -142,7 +142,7 @@ Types can be qualified with `const` and `*`. Types are written left-to-right, so

``` cpp title="Example: Type qualifiers"
// A const pointer to a non-const pointer to a const i32 object
p: const * * const i32; //
p: const * * const i32;
```

### Literals
Expand Down Expand Up @@ -272,7 +272,7 @@ There are two kinds of `is`:

### `as` — safe casts and conversions

An `x as T` expression allows safe type casts. `x` must be an object or expression, and `T` must be a type. It supports both static and dynamic typing, including customization with support for the standard dynamically tyuped libraries `std::variant`, `std::optional`, and `std::any` provided in the box. For example:
An `x as T` expression allows safe type casts. `x` must be an object or expression, and `T` must be a type. It supports both static and dynamic typing, including customization with support for the standard dynamically typed libraries `std::variant`, `std::optional`, and `std::any` provided in the box. For example:

``` cpp title="Example: Using as"
main: () = {
Expand Down Expand Up @@ -323,7 +323,7 @@ test: (x) = {
// Sample call site
test(42);
// Behaves as if the following function were called:
// test: (x) = { std::cout << (:std::string = "the answer") << "\n";; }
// test: (x) = { std::cout << (:std::string = "the answer") << "\n"; }
// (and that's why inspect alternatives are introduced with '=')
```

Expand Down Expand Up @@ -542,7 +542,7 @@ skat_game: @enum<i16> type = {

Consider `hearts`: It's a member object declaration, but it doesn't have a type (or a default value) which is normally illegal, but here it's okay because the `@enum<i16>` metafunction fills them in: It iterates over all the data members and gives each one the underlying type (here explicitly specified as `i16`, otherwise it would be computed as the smallest signed type that's big enough), and an initializer (by default one higher than the previous enumerator).

Unlike C `enum`, this `@union` is scoped and strongly type (does not implicitly convert to the underlying type.
Unlike C `enum`, this `@enum` is scoped and strongly typed (does not implicitly convert to the underlying type.

Unlike C++11 `enum class`, it's "just a `type`" which means it can naturally also have member functions and other things that a type can have:

Expand Down Expand Up @@ -616,7 +616,7 @@ Unlike C `union`, this `@union` is safe to use because it always ensures only th

Unlike C++11 `std::variant`, this `@union` is easier to use because its alternatives are anonymous, and safer to use because each union type is a distinct type. [^variant]

Each `@union` type has its own type-safe name, has clear and unambiguous named members, and safely encapsulates a discriminator to rule them all. Sure, it uses unsafe casts in the implementation, but they are fully encapsulated, where they can be tested once and be safe in all uses. That makes @union:
Each `@union` type has its own type-safe name, has clear and unambiguous named members, and safely encapsulates a discriminator to rule them all. Sure, it uses unsafe casts in the implementation, but they are fully encapsulated, where they can be tested once and be safe in all uses.

Because a `@union type` is still a `type`, it can naturally have other things normal types can have, such as template parameter lists and member functions:

Expand Down
2 changes: 1 addition & 1 deletion docs/reference-cppfront.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ When cppfront compiles such a mixed file, it just passes through the Cpp1 code a

- **Code written in Cpp1 is order-dependent as usual.** When either the caller or the callee (or both) are written in Cpp1 syntax, the callee must be declared before the caller.

However, this source file is not valid, because it tries to nest Cpp2 code inside Cpp1 code, and vice versa:
However, the following source file is not valid, because it tries to nest Cpp2 code inside Cpp1 code, and vice versa:

``` cpp title="ERROR.cpp2 — this is NOT allowed" linenums="1" hl_lines="5 6 9 14"
#include <iostream> // Cpp1 syntax
Expand Down