←back to thread

196 points svlasov | 2 comments | | HN request time: 0s | source
Show context
stefanos82 ◴[] No.40851614[source]
Can I ask a naive question that consists of two parts and please don't flame me? lol

  * What type of problems static reflection could solve, in general?
  * Are there specific cases and / or situations where static reflection could resolve such case, even simplify an unnecessary complexity?
replies(8): >>40851661 #>>40851675 #>>40851709 #>>40851795 #>>40851942 #>>40852552 #>>40853159 #>>40853615 #
quotemstr ◴[] No.40851675[source]
> What type of problems static reflection could solve, in general?

Imagine making a plain

    struct Point { float x; float y; };
and wanting to serialize it to JSON without further ceremony
replies(2): >>40851792 #>>40853917 #
throwway120385 ◴[] No.40851792[source]
This is the thing that's driving me away from C++ very quickly. A big part of our code base is code that handles this, and it either has to be in a DSL and constantly recompiled or we have to make a bunch of boilerplate. It's a huge problem for the language not to be able to do this.
replies(3): >>40852051 #>>40852750 #>>40853258 #
germandiago ◴[] No.40853258[source]
I suggest you to take a look at Boost.Describe.

I have a scripting layer in a game that needs to set properties in a C++ Model. I used a single Boost.Describe macro per struct and a generic get/set property. It worked very well and made me get rid of a lot of boilerplate.

https://www.boost.org/doc/libs/develop/libs/describe/doc/htm...

replies(2): >>40853792 #>>40857633 #
beached_whale ◴[] No.40853792[source]
Boost.PFR is really neat and doesn’t need manual mapping for aggregate types
replies(1): >>40855268 #
1. germandiago ◴[] No.40855268{3}[source]
What I needed is accessing thosr by name. So PFR won't do.
replies(1): >>40861684 #
2. beached_whale ◴[] No.40861684[source]
Should be able to build that on if it isnt there. But at runtime the type would need to be a sum type like variant.