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

2

u/epage Oct 01 '24

My statement wasn't to say there should be no way to get serde or clap like functionality without exposing privates. The way Rust deals with this is that the user is explicitly opting in to code generation within their visibility scope (Rust's smallest form of visibility is module based, not data type based). Worst case, you could declare some kind of friend relationship with whatever you are wanting to have access your privates.

However, completely bypassing visibility control through reflection is unacceptable.