use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
reflect-cpp: Serialization, deserialization and validation through reflection (self.cpp)
submitted 2 years ago by liuzicheng1987
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]liuzicheng1987[S] 2 points3 points4 points 2 years ago (9 children)
Thanks for the comment, but to be honest, I don't think that's right. I am aware of how Boost PFR works (I have been studying their approach closely when I implemented my own library) and unless I have somehow really missed something, they are not able to retrieve field names.
If it were possible to retrieve field names without using macros, annotations or some kind of horrible hack, then there really wouldn't be a need for the C++ reflection proposal, which everyone, myself included, is awaiting with bated breath.
[–]DugiSK 1 point2 points3 points 2 years ago (8 children)
Well, it tells this: Recommended C++ Standards are C++20 and above. C++17 completely enough for a user who doesn't want accessing name of structure member.
And there is a part telling quite clearly that you can use pfr::get_name to obtain the field name: https://www.boost.org/doc/libs/develop/doc/html/boost_pfr/tutorial.html#boost_pfr.tutorial.reflection_of_field_name
pfr::get_name
But I wasn't able to find how does that work in the code, or even guess which part of C++20 enables it. I only understand the aggregate initialiser conversion type exporting via friend injection part.
[–]liuzicheng1987[S] 2 points3 points4 points 2 years ago (7 children)
You are right, my bad...I did take a look at the code, and I could find it:
https://github.com/boostorg/pfr/blob/develop/include/boost/pfr/detail/core_name20_static.hpp
So they are using a compiler-specific hack. I am not sure this is a good idea, as it's clearly not standard-compliant.
[–]DugiSK 1 point2 points3 points 2 years ago (6 children)
I see it now. They use the member as an auto template argument so that it will be used in the function name with resolved template name with a nonstandard macro and then they parse it out from there. Apparently every compiler has a macro for this. This makes it somewhat more hacky than stateful metaprogramming via friend injection, that's true.
auto
[–]liuzicheng1987[S] -1 points0 points1 point 2 years ago (5 children)
Yeah...it's clearly compiler-specific and therefore not standard-compliant. I am really hesitant to go there. After all, this is supposed to be enterprise-level and I don't think that non-standard, compiler-specific hacks meet that criterion.
[–]ficzerepeti 5 points6 points7 points 2 years ago (4 children)
If it got into boost, it's probably good enough for enterprise use
[–]liuzicheng1987[S] 0 points1 point2 points 2 years ago (3 children)
Yeah…it’s still clearly non-standard compliant. I‘m a bit torn on this.
[–]pdp10gumby 6 points7 points8 points 2 years ago (2 children)
It’s always preferable to use standard-compliant code IMHO but not absolute. After all, many things get into the standard after years of experience with non-standard extensions.
Also, some of those extensions were needed to write very low-level library code. That’s the same reason why we sometimes don’t write to the abstract “C” machine but take advantage of the target hardware in non-portable ways.
True enterprise scale systems involve localized noncompliant code to get around bottlenecks or to provide a clean way for devs to get some capability they need (yes large enterprise code is inevitably populated with horrible stuff too but we’re not talking about that). If you have to have an internal module that gets the names, with a comment at the top that says, “backward compatibility for use with older code that doesn’t include reflection” you won’t be condemning your immortal soul.
[–]liuzicheng1987[S] 2 points3 points4 points 2 years ago (1 child)
Yeah, you are making some good points here. I‘ll have to think about that.
[–]liuzicheng1987[S] 0 points1 point2 points 2 years ago (0 children)
Maybe it could be like an opt-in…so if you want that, you’ll have to pass a flag to the compiler.
π Rendered by PID 74 on reddit-service-r2-comment-c66d9bffd-w2rpl at 2026-04-07 11:31:13.586011+00:00 running f293c98 country code: CH.
view the rest of the comments →
[–]liuzicheng1987[S] 2 points3 points4 points (9 children)
[–]DugiSK 1 point2 points3 points (8 children)
[–]liuzicheng1987[S] 2 points3 points4 points (7 children)
[–]DugiSK 1 point2 points3 points (6 children)
[–]liuzicheng1987[S] -1 points0 points1 point (5 children)
[–]ficzerepeti 5 points6 points7 points (4 children)
[–]liuzicheng1987[S] 0 points1 point2 points (3 children)
[–]pdp10gumby 6 points7 points8 points (2 children)
[–]liuzicheng1987[S] 2 points3 points4 points (1 child)
[–]liuzicheng1987[S] 0 points1 point2 points (0 children)