Skip to content

Fix doc typo: Updated ..< instead of ... for range operations in doc common.md #1254

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 1 commit into from
Sep 24, 2024
Merged
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
6 changes: 3 additions & 3 deletions docs/cpp2/common.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ if !vec.empty() {
| `+` | `#!cpp +100` | `#!cpp +100` |
| `-` | `#!cpp -100` | `#!cpp -100` |

The operators `.`, `..`, `*`, `&`, `~`, `++`, `--`, `()`, `[]`, `...`, `..=`, and `$` are postfix. For example:
The operators `.`, `..`, `*`, `&`, `~`, `++`, `--`, `()`, `[]`, `..<`, `..=`, and `$` are postfix. For example:

``` cpp title="Using postfix operators"
// Cpp1 examples, from cppfront's own source code:
Expand All @@ -216,11 +216,11 @@ Postfix notation lets the code read fluidly left-to-right, in the same order in
| `#!cpp --` | `#!cpp iter--` | `#!cpp --iter` |
| `(` `)` | `#!cpp f( 1, 2, 3)` | `#!cpp f( 1, 2, 3)` |
| `[` `]` | `#!cpp vec[123]` | `#!cpp vec[123]` |
| `...` | `#!cpp v.begin()...v.end()` | `#!cpp std::ranges::subrange(v.begin(), v.end())` |
| `..<` | `#!cpp v.begin()..<v.end()` | `#!cpp std::ranges::subrange(v.begin(), v.end())` |
Copy link
Contributor

@gregmarr gregmarr Aug 23, 2024

Choose a reason for hiding this comment

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

@hsutter Should these two range operators be in the binary operators table instead of the unary operators table? Should the ... pack expansion then be in this table, or is it okay as the note below?

Copy link
Owner

Choose a reason for hiding this comment

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

Good point, I'll look at that post-merge

Copy link
Contributor

Choose a reason for hiding this comment

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

@hsutter

Note: The ( ), [ ], ..<, and ..= operators are treated as postfix unary operators, though they can take additional arguments.

I can kinda see how () and [] as pairs are considered postfix since they apply their contents to the thing to the left. Can you explain how ..< and ..= are treated as postfix unary? I don't understand what that means.

| `..=` | `#!cpp 1..=10` | `#!cpp std::views::iota(1, 11)` |
| `$` | `val$` | _reflection — no Cpp1 equivalent yet_ |

> Note: The `...` pack expansion syntax is also supported. The above `...` and `..=` are the Cpp2 range operators, which overlap in syntax.
> Note: The `...` pack expansion syntax is also supported.

> Note: Because `++` and `--` always have in-place update semantics, we never need to remember "use prefix `++`/`--` unless you need a copy of the old value." If you do need a copy of the old value, just take the copy before calling `++`/`--`. When you write a copyable type that overloads `operator++` or `operator--`, cppfront generates also the copy-old-value overload of that function to support natural use of the type from Cpp1 code.

Expand Down
Loading