←back to thread

196 points svlasov | 3 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 #
1. sankhao ◴[] No.40853917[source]
This is doable in c++20 https://github.com/stephenberry/glaze
replies(1): >>40854242 #
2. _flux ◴[] No.40854242[source]
That's pretty neat! What's the C++20 feature that enables this?
replies(1): >>40855636 #
3. gpderetta ◴[] No.40855636[source]
From a quick look, generalized constexpr evaluation, but in practice it relies on parsing non-portable decorated function names from things like source location. An ugly, slow, but effective hack.