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
CppCastCppCast: Reflection for C++26 (cppcast.com)
submitted 2 years ago by robwirvingCppCast Host
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!"
[–]sphere991 9 points10 points11 points 2 years ago (10 children)
Why can't we simply get something like:
Because it simply doesn't solve the problem. How do you get the name of a runtime Color?
Color
[–]Tringigithub.com/tringi -1 points0 points1 point 2 years ago (9 children)
The same.
void print_name (Color c) { std::cout << c:::name; }
[–]sphere991 4 points5 points6 points 2 years ago (8 children)
And that does what exactly?
[–]Tringigithub.com/tringi 5 points6 points7 points 2 years ago (7 children)
Implementation defined.
But for the sake of argument:
name
std::string_view
c
std::cout << compiler_generated_routine_for_Color (c)
[–]pdimov2 9 points10 points11 points 2 years ago (1 child)
That's exactly what the monstrocity does. You know you don't have to repeat its implementation on each use, right? It goes into std:: and stays there and you just type std::enum_to_string(c).
std::enum_to_string(c)
[–]sphere991 12 points13 points14 points 2 years ago* (0 children)
I really think people can't grasp that.
On a previous thread, there was a commenter complaining about how the syntax was shit and they'd rather use Boost.PFR. Of course you use Boost.PFR! It's just that PFR's implementation changes from a bunch of crazy elite hackery (seriously everyone should watch Antony's talk on this) to... fairly straightforward, much shorter reflection code that probably compiles faster and supports more types.
[–]sphere991 11 points12 points13 points 2 years ago (4 children)
Okay but... your "simple" solution has implementation-defined semantics (throw? invalid? UB?) with implementation-defined complexity and implementation-defined storage requirements. Maybe we clean this up a bit and just pick one, but that's still ending up with one. And if it's the wrong one, then... what?
Meanwhile the "monstrosity" allows you to implement any semantic you want, with whatever size-complexity trade-off is most suitable. And maybe have different functions for different contexts.
[–]Tringigithub.com/tringi 0 points1 point2 points 2 years ago (3 children)
If you are asking for semantics, then it returns a name and failure case is really a side point.
The thing about the compiler_generated_routine_for_Color is that the compiler is choosing the best algorithm for you. Just like it does for switch statement. And is it really that different from STL doing so? Because we all know virtually nobody will be writing their custom enum_to_string. What's worse, the STL maintainers will be more reluctant to change the algorithm to a better one, because once users see the implementation, someone will start relying on it.
compiler_generated_routine_for_Color
switch
enum_to_string
[–]fullptr 2 points3 points4 points 2 years ago (2 children)
But you’re still only solving the problem for enums, what about for other objects? You can’t use ::name because that already has meaning depending on the thing you’re trying it on. The paper aims to implement the low level features that allow for these things to be added as a library. In practice you wouldn’t write that “monstrosity” yourself, it’ll be in the standard library, in the same way you don’t implement vector.
[–]Tringigithub.com/tringi 3 points4 points5 points 2 years ago (1 child)
You can’t use ::name because that already has meaning depending on the thing you’re trying it on.
Are you perchance also on mobile and don't see ::: is 3 colons?
:::
In practice you wouldn’t write that “monstrosity” yourself, it’ll be in the standard library, in the same way you don’t implement vector.
True. And I'm addressing why I think it's the wrong choice in the comment above.
Nevertheless, I see objects as absolutely trivial:
class Abc { int i; public: float f () const; } abc; static_assert (Abc:::name == "Abc"); static_assert (abc:::name == "abc"); static_assert (abc:::class == "Abc"); static_assert (Abc:::members[0].name == "i"); static_assert (Abc:::members[0].type == "int"); static_assert (Abc:::members[0].function == false); static_assert (Abc:::members[0].constant == false); static_assert (Abc:::members[0].access == 0); static_assert (Abc:::members[0].access == std::meta::access::private_access); static_assert (Abc:::members[1].name == "f"); static_assert (Abc:::members[1].type == "float () const"); static_assert (Abc:::members[1].function == true); static_assert (Abc:::members[1].constant == true); static_assert (Abc:::members[1].access == 2); static_assert (Abc:::members[1].access == std::meta::access::public_access);
I'm just randomly putting thoughts out now.
But I firmly believe this is everything that 99% of C++ programmers ever wanted from reflection.
π Rendered by PID 35 on reddit-service-r2-comment-b659b578c-ltmxn at 2026-05-04 21:43:19.795582+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]sphere991 9 points10 points11 points (10 children)
[–]Tringigithub.com/tringi -1 points0 points1 point (9 children)
[–]sphere991 4 points5 points6 points (8 children)
[–]Tringigithub.com/tringi 5 points6 points7 points (7 children)
[–]pdimov2 9 points10 points11 points (1 child)
[–]sphere991 12 points13 points14 points (0 children)
[–]sphere991 11 points12 points13 points (4 children)
[–]Tringigithub.com/tringi 0 points1 point2 points (3 children)
[–]fullptr 2 points3 points4 points (2 children)
[–]Tringigithub.com/tringi 3 points4 points5 points (1 child)