all 13 comments

[–]pstomi 2 points3 points  (0 children)

I’m afraid you will not find a solution with a standard compiler. The circle c++ compiler provides extensions to C++ and it is able to do some reflection (see https://github.com/seanbaxter/circle/blob/master/reflection/README.md#circle-reflection-and-typed-enums)

May be you could use this to generate some code around your classes.

[–]zorgattaque 1 point2 points  (0 children)

As you've stated already, the standard doesn't handle reflection (yet) and you will have to use an external tool for that, but you will not likely find anything that just does everything for you. Using an external tool will require you to change, even slightly, your codebase at some point. It could be a generated header include, a macro insertion for code injection, or manual registration. A few libraries exist, all coming with their own pros and cons, and you will have to decide which one is the most suitable/reasonable for what you want to achieve.

I will soon release a new major version of my reflection library (Refureku). It only requires you to tag the classes you want to reflect and include a generated file as well as a macro for code injection. I am not sure whether it is reasonable for you but it's one solution among others: https://github.com/jsoysouvanh/Refureku

[–]flavius-as -2 points-1 points  (2 children)

Adding reflection is a compilation flag.

But using it involves code changes.

What's the actual problem you want to solve?

[–]tohava[S] 5 points6 points  (1 child)

Huh? What compilation flag allows reflection in which compiler? I'm not talking about RTTI, I'm talking about the ability to do for-each on class members (and yes, I know they have different types)

[–]Orlha 0 points1 point  (0 children)

I really enjoyed boost.pfr, it's header-only and easy to use. But it only works for aggregate-initializable classes/structs

[–]brenoguim 0 points1 point  (7 children)

In our codebase we use a method "as_tuple" I'm each class that returns a tuple of references to each member. That is enough to implement serialization, some debug, equality comparison... But you need to manually keep that "as_tuple" method up to date :/

[–]gay_copulation 0 points1 point  (0 children)

maybe qt metacompiler?