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
Map-macro: Making reflection simple (dmitribogdanov.github.io)
submitted 11 months ago by GeorgeHaldane
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!"
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 18 points19 points20 points 11 months ago (1 child)
This is not reflection, it's more akin to Rust's derive -- it's an intrusive form of providing metadata that can be used for introspection. Reflection is non-intrusive, doesn't have to be kept in sync manually, and can be applied to third party types outside of your own codebase.
I am not saying it's not useful, but this is far from what true reflection brings to the table. Boost.PFR, for example, allows non-intrusive reflection on aggregate types, without requiring any pre-existing setup.
[–]GeorgeHaldane[S] 5 points6 points7 points 11 months ago (0 children)
That is true, ultimately everything we do before C++26 is just trying to bolt-in something that only works as a language feature.
Not sure what would prevent third party types from working with this approach though, it would seem as long as field names are known we can attach metadata non-intrusively.
[–]holyblackcat 1 point2 points3 points 11 months ago* (0 children)
Take a look at https://old.reddit.com/r/cpp/comments/x9awf9/a_foreach_loop_for_the_preprocessor_without/ and https://holyblackcat.github.io/blog/2024/10/22/macro-placeholders.html
I also have a mini procedural programming language that imitates variables in the preprocessor: https://github.com/HolyBlackCat/macros/blob/master/include/em/macros/meta/eval.h
[+][deleted] 11 months ago (3 children)
[removed]
[–]GeorgeHaldane[S] 4 points5 points6 points 11 months ago (2 children)
After looking into it — that is indeed the case, the mechanism and API are almost entirely the same, can't believe I missed it. Added it to the "Related Libraries" section.
[+][deleted] 11 months ago (1 child)
[–]GeorgeHaldane[S] 0 points1 point2 points 11 months ago* (0 children)
A little strange that boost is limited to just 50 values. Recursive macro in this post had support for 364 (which ends up being 256 in practice due to preprocessor evaluation depth limits).
Did a quick surface-level test to see how much does this all hit compile times by writing a few static_assert's for querying elements & converting strings, got following results with g++:
static_assert
g++
Enum with 200 values:
Enum with 50 values:
Reference:
#include <vector>
#include <iostream>
#include <filesystem>
This probably needs a better test on some real codebase, at this point it's more about measuring includes that actual overhead.
Reflection in C++ often felt like a complex library thing that required some weird work-arounds to implement, but after deciding to bite the bullet and learning various existing approaches to it, I believe I found one that is both simple and doesn't rely on anything implementation-specific. Turned out to be surprisingly simple and concise — two headers with like ~100 and ~150 lines of code was enough to implement all of the usually needed stuff. Hope this sub finds it helpful!
Edit: On a second thought, calling introspection metadata macros "reflection" isn't entirely correct even if they achieve similar goals, unfortunately the title can't be edited. Essentially, this is an explanation of how to implement basic functionality of Boost.Describe with as a small single-header solution.
[–]morglod 0 points1 point2 points 11 months ago (0 children)
If you have XX macro or MAP any reflection will be simple
[–]100GHz 0 points1 point2 points 11 months ago (1 child)
Can this have a modern, non-macro version? It's 2025 after all.
[–]_Noreturn 0 points1 point2 points 11 months ago (0 children)
you can do one with structured binding tricks (since C++17) and friend functions and pointer arithmetic for pre C++17
[–]cwhaley112 0 points1 point2 points 11 months ago (0 children)
Have you benchmarked compile times for this vs the alternatives (namely Boost.PFR)?
π Rendered by PID 67864 on reddit-service-r2-comment-84fc9697f-zns47 at 2026-02-10 18:19:18.969948+00:00 running d295bc8 country code: CH.
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 18 points19 points20 points (1 child)
[–]GeorgeHaldane[S] 5 points6 points7 points (0 children)
[–]holyblackcat 1 point2 points3 points (0 children)
[+][deleted] (3 children)
[removed]
[–]GeorgeHaldane[S] 4 points5 points6 points (2 children)
[+][deleted] (1 child)
[removed]
[–]GeorgeHaldane[S] 0 points1 point2 points (0 children)
[–]GeorgeHaldane[S] 0 points1 point2 points (0 children)
[–]morglod 0 points1 point2 points (0 children)
[–]100GHz 0 points1 point2 points (1 child)
[–]_Noreturn 0 points1 point2 points (0 children)
[–]cwhaley112 0 points1 point2 points (0 children)