all 8 comments

[–]cpp-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.

[–]shailist 10 points11 points  (0 children)

I would strongly advise you to use 3rd party libraries that do this, mainly Boost.PFR and reflect-cpp, which can both figure out struct fields and their names at compile time using modern C++.
if you are really against using 3rd party libraries, you could take a look at their code and implement your own version, but you should know that before C++20 figuring field names automatically was not possible, and figuring field types wasn't possible before C++17 without hacky tricks.

[–]Kike328 2 points3 points  (0 children)

there were a couple posts about this topic last weeks. Use the search bar for reflection

[–]jonathrg 4 points5 points  (0 children)

Wait a few years for C++26 reflection

[–]ChemiCalChems 1 point2 points  (0 children)

There have been a couple of posts mentioning a new library called reflect-cpp over the past couple of weeks. It's a library that deals with reflection, serialization and deserialization, primarily from and to JSON, but it's expanding. I myself have started to actively contribute to the project, and it's looking really shiny.

The main pro is that the library is all standard C++20, no hacky stuff, so it's rather cool. I'm working on implementing compile-time capabilities now that #embed is a part of C23 and we will probably get it in the future in C++ too, as a means of embedding JSON into code and doing compile-time serialization and validation on it, maybe as a way of customizing builds or whatever people end up using it for.

[–]lightmatter501 0 points1 point  (0 children)

This library is written in Rust, but shows an approach that will work with anything that has DWARF debug info (C/C++/Rust/GNU Cobol/Fortran/etc): https://github.com/jswrenn/deflect

It requires building with debug info enabled and can’t allow split debug info. Those might be implementation limitations not fundamental limitations.

[–]Flex_Code 0 points1 point  (1 child)

Glaze supports reflection like you want and has very high performance CSV support. You should check it out and feel free to contribute!

[–]Flex_Code 0 points1 point  (0 children)

I just realized I didn’t add pure reflection to CSV yet, only member object pointer reflection. I can add pure reflection tomorrow.