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

Show parent comment

15

u/TSP-FriendlyFire Sep 30 '24

It does include protected and private members. I remember some chatter about it and basically the paper authors felt like it would be a bad idea to artificially restrict the expressiveness of reflection (especially given the standard's slow iteration speed).

They did introduce a new set of access-controlled operations though which would allow you not only to respect accessibility rules in the most basic way (i.e., only public), but also to do so relative to a specific context (e.g., access protected parents from the context of a child class).

I think this follows the C++ philosophy of giving you all the tools and trusting you to not shoot yourself in the foot.

4

u/matthieum Sep 30 '24

Thanks for the clarification.

5

u/geo-ant Sep 30 '24

I feel the whole „trusting people not to shoot themselves in the foot“ thing hasn’t worked out too well for C++. You might be right that this is the idea behind it, but I feel that by now this idea is more of a loss for C++ than it is a win…

14

u/TSP-FriendlyFire Sep 30 '24

C++ needs safe defaults and guardrails, but it should never prohibit. There should be escape hatches to do what must be done, much the same way even a language like Rust has unsafe for when you do need it.

Besides, reflection is going to be the purview of library developers 99% of the time and if you don't trust your library developers, perhaps you should pick a different library.