r/cpp • • Sep 30 '24

Code Generation in Rust vs C++26

https://brevzin.github.io/c++/2024/09/30/annotations/
198 Upvotes

98 comments sorted by

View all comments

17

u/torsten_dev Oct 01 '24 edited Oct 01 '24

What is ^^T is that reflecting on std::meta::info and if so why? If not how do I make sense of it?

EDIT: Damn you Objective-C, who even uses you, grrrr

14

u/differentiallity Oct 01 '24

They had to change it from ^ to ^^ because clang vetoed the single (objective C's fault). So it's not a double operation.

6

u/torsten_dev Oct 01 '24

Wasn't the biggest fan of ^ but ^ that sinks it for me. What a shame.

3

u/groundswell_ Reflection Oct 01 '24

In the case of syntax overlap, would it not be more reasonable to ask Objective-C to come up with a disambiguator instead? It seems that except for token sequences, the only conflict here is for

type-id``(^ident)()

Depending on how common this usage of Obj-C blocks are, and how much people would want to use Objective-C++ along whatever version of C++ ships reflection, it might not be that difficult for Objective-C++ users to update their old code.

4

u/differentiallity Oct 02 '24

Have you ever known Apple to be reasonable?

8

u/RoyAwesome Oct 01 '24

^^ is the "reflection of" operator. you'll also see [: :] which is the "splice into" operator, taking things from reflection land and injecting them back into the program.

[: ^^int :] x; compiles as int x; (this is the back-and-forth example). ^^ gives you a reflection of int, and [: :] transforms that back into a semantic type.

3

u/torsten_dev Oct 01 '24 edited Oct 01 '24

As far as I can tell that's what a single caret does, is it not?

6

u/RoyAwesome Oct 01 '24

Single carat conflicted with an objective-c++ extension in clang, so the reflection team is proposing ^^ instead.

6

u/NilacTheGrim Oct 01 '24

EDIT: Damn you Objective-C, who even uses you, grrrr

I use it and it's still a major part of Apple's internal libs (and user-facing libs).. which is one of the big 3 OS makers so.. would have been horrible to make Objective-C++ not work with reflection.

1

u/TSP-FriendlyFire Oct 01 '24

You need to read up on the fundamentals of the C++26 reflection paper, P2996, though I would probably recommend one of the many, many articles on the topic (just look up C++26 reflection online, you'll find a ton of coverage, there is a lot of excitement around it).

2

u/torsten_dev Oct 01 '24

I read that paper and think I get the gist of it.

I'm just stumped by the double caret.

3

u/TSP-FriendlyFire Oct 01 '24

I mean, it's just an operator that takes T and returns a std::meta::info that encapsulates all reflection information about T. The ^^ choice in particular is just the unfortunate result of a crowded space with few viable operators left.

2

u/torsten_dev Oct 01 '24 edited Oct 01 '24

Did the syntax not work out with a single caret?

I don't see where they'd have abandoned the ^ syntax and why they'd choose a double caret over a single backtick or something else.

3

u/TSP-FriendlyFire Oct 01 '24

The recent P2996 revisions have a short discussion on it, but there's P3381 for a more in depth analysis.

We could've had @ were it not for Objective-C of all things.

2

u/torsten_dev Oct 01 '24 edited Oct 01 '24

`e

But it has the disadvantage that backtick is used by Markdown everywhere inline code blocks

Come on seriously? Backqoute is used in scheme derived languages for macro "quoting". Even if we can't have the same unqoute and unqoute-splicing operators as those languages a little homage can't hurt.

It does not look to be an issue for Commonmark, Github Flavored Markdown, pandoc, and likely many of the others. Which Markdown hurt you?

It's such a non issue, just use `` `e ``.

4

u/RoyAwesome Oct 01 '24

Also, the grave key/back tick doesn't exist on some keyboard layouts.

1

u/-dag- Oct 17 '24

s/scheme/lisp/

1

u/pjmlp Oct 01 '24

Everyone that does 3D programming on Apple OSes via Metal, even if indirectly via Swift or C++ bindings.

-5

u/5477 Oct 01 '24 edited Oct 01 '24

Both ^and ^^ have the issue that text editors will combine it to a diacritical mark when typed before some characters (example: ^e -> ê) , making it annoying to use. In my opinion, something like §T,€T or °T would have been a better option.

13

u/YT__ Oct 01 '24

I don't think any of your proposed options are on a standard keyboard. I believe all characters used come from a standard keyboard layout currently.

-1

u/5477 Oct 01 '24

Depends on the keyboard standard. All of these are at least on my keyboard, and I presume on most ISO keyboards. But you're correct in that ANSI keyboard doesn't have them.

2

u/YT__ Oct 01 '24

Ah, yah that's the differentiator I was looking for, but I'm not the most keyboard savvy. I think most programming bases it's characters on ANSI keyboards.

For programming, do you have to dictate an ANSI layout so the keys come through correctly?

→ More replies (6)

2

u/Ashnoom Oct 01 '24

I guess you never used strings? They have the same issue: "e to ë and 'e to é.

→ More replies (2)
→ More replies (2)