Skip to content
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

docs: fix some typos and confusing wording #976

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Here we can see more of how Cpp2 makes it features work.
**How: Simple and safe by default.**

- **Line 9:** CTAD just works, because it turns into ordinary C++ code which is CTAD-aware.
- **Lines 10-11:** The accesses of `words[0]` and `words[1]` are bounds-checked nonintrusively at the call site by default. Because it's nonintrusive, it works seamlessly with all existing container types that are `std::ssize`-aware, when you use them from safe Cpp2 code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but if you look earlier in the document it does say std::size, so I changed this to be consistent with the earlier mention. Which version should we keep? std::size, std::ssize, both, something else?

As additional context, what the doc say is "std::size-aware" really means satisfying this concept:
https://github.com/hsutter/cppfront/blob/main/include/cpp2util.h#L531-L532

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started a review, and updated this in my local version to list both of them. For details, it uses ssize when you use a signed value and size for an unsigned value.

- **Lines 10-11:** The accesses of `words[0]` and `words[1]` are bounds-checked nonintrusively at the call site by default. Because it's nonintrusive, it works seamlessly with all existing container types that are `std::size`-aware, when you use them from safe Cpp2 code.
- **Line 16:** String interpolation performs the string capture of `msg`'s current value via `cpp2::to_string`. That uses `std::to_string` when available, and it also works for additional types (such as `bool`, to print `false` and `true` instead of `0` and `1`, without having to remember to use `std::boolalpha`).

**How: Simplicity through generality + defaults.**
Expand Down
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
Loading