From c3637e1deab173d79ef6e6e63034abcaa41aed18 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Wed, 14 Feb 2024 13:14:48 +0100 Subject: [PATCH 1/2] docs: fix some typos and confusing wording --- docs/index.md | 2 +- docs/reference-cpp2.md | 12 ++++++------ docs/reference-cppfront.md | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/index.md b/docs/index.md index d9a2c1b4e..918859ef6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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. +- **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.** diff --git a/docs/reference-cpp2.md b/docs/reference-cpp2.md index b3c3af60a..4a943796f 100644 --- a/docs/reference-cpp2.md +++ b/docs/reference-cpp2.md @@ -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 @@ -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 @@ -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: () = { @@ -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 '=') ``` @@ -542,7 +542,7 @@ skat_game: @enum 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` 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: @@ -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: diff --git a/docs/reference-cppfront.md b/docs/reference-cppfront.md index e0a50bd79..2e5cd39f3 100644 --- a/docs/reference-cppfront.md +++ b/docs/reference-cppfront.md @@ -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 // Cpp1 syntax From 9ae681286214b50ccba705146c47e8e570b35d94 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Wed, 14 Feb 2024 18:22:50 +0100 Subject: [PATCH 2/2] restore std::ssize --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 918859ef6..d9a2c1b4e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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::size`-aware, when you use them from safe Cpp2 code. +- **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. - **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.**