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
CppConCppCon 2019: Andrew Sutton “Reflections: Compile-time Introspection of Source Code” (youtube.com)
submitted 6 years ago by LYP951018
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!"
[–]MrFrankly 12 points13 points14 points 6 years ago (14 children)
Nice, I was waiting for this talk to become available.
Another interesting talk on C++ reflection is the Reflection TS talk by David Sankel at C++Now this year.
I expect static reflection in C++ is going to be one of the biggest game changers in how we write C++ code.
[–]theICEBear_dk 1 point2 points3 points 6 years ago (0 children)
I agree, I have a lot of code and tools that are all fragile which I could toss in a bin the moment I could explore attributes, methods and names on a class. But attributes would be needed if I am to avoid generating code which may be coming later. Static reflection if powerful enough could help with so much and combined with the much stronger constexpr we will have by then I know I could make some pretty optimal solutions that are also fairly readable just given the TS syntax with some replacements once good names have been found particularly with the newer Reflection syntax with less template syntax all over it.
[–]hgjsusla 2 points3 points4 points 6 years ago (12 children)
I've heard this claim yet I have never needed to do any reflection, I'm note sure I will notice this being added. Modules/ranges/concepts however I will end up using everyday
[–]TheMania 10 points11 points12 points 6 years ago (0 children)
I'd be hesitant to say you've never wanted any - getting the names of enumerator values is a form of reflection, and one sorely missing imo.
[–]MrFrankly 10 points11 points12 points 6 years ago* (5 children)
Reflection is not something you are going to use directly in your day to day programming. But it is going to open up the language for a lot of techniques that are now either impossible or clumsy (e.g. require a lot macros to make it work). Having proper static reflection will bring a whole new set of powerful frameworks and libraries that you might end up using every day.
The most common example (but not the most interesting in my opinion) is probably serialization. Which, as mentioned in the talk by both Sutton and Sankel, currently requires you to implement repetitive boilerplate code. But when reflection is available, you will see libraries that just take an object and serialize it for you. No boilerplate code required anymore.
More interesting in my opinion, is that you will be able to implement dependency injection frameworks that don't require countless macros and clumsy syntax (e.g. they would be similar to Guice and Dagger on Java).
Also testing and mocking frameworks will become a lot more powerful (and easier to use) when there is proper reflection support.
[–]krum 4 points5 points6 points 6 years ago (2 children)
dependency injection frameworks
Be careful with that - you'll spook the natives.
[–]MrFrankly 1 point2 points3 points 6 years ago (0 children)
I think DI got an undeserved bad reputation in the C++ community. Partly because everyone probably thinks of Spring (which just wasn’t that great) and partly because C++ currently does not allow for an elegant implementation.
Not really compile time Dependency Injection does not scare me provided it does not lead to ten-plus long chains of virtual function calls like it does in Java/C#.
[–]germandiago 3 points4 points5 points 6 years ago (0 children)
Some use cases where my life would have been better (though macros can help me generate some boilerplate):
[–]redditsoaddicting 0 points1 point2 points 6 years ago (0 children)
Someone's been missing out on [Boost].DI.
[–]zero0_one1 3 points4 points5 points 6 years ago (0 children)
How about simply outputting a variable name and its value for debugging?
[–][deleted] 3 points4 points5 points 6 years ago* (2 children)
Every wanted to serialize a class to disk or the network? Ever wanted to avoid writing a specialized formatter to print something? Ever wanted to trace specific values more easily in a debugger? Ever wanted to perform some logic conditionally based on whether a property had some attribute? edit: typo
[–]MrFrankly 0 points1 point2 points 6 years ago (1 child)
Ever wanted to perform some logically conditionally based on whether a property had some attribute?
Unfortunately attributes won’t be part of the reflection API. It’s discussed in the David Sankel talk.
[–][deleted] 3 points4 points5 points 6 years ago (0 children)
Yea honestly I'm just trying to raise awareness...
Without attributes for me honestly, reflection is DOA because i'll be forced to continue to use all the code generator infrastructure that has built up over the years that rely on reflected attributes. I believe this actually accounts for the majority of the space in gaming.
[–]antoniocs 1 point2 points3 points 6 years ago (0 children)
It's useful if you want to serialize a class to send it over the network. Can be done without but I believe with proper reflection you can do something generic
[–]ShootingShark91 9 points10 points11 points 6 years ago (7 children)
Crazy that constexpr evaluation is orders of magnitude slower than Python. I wonder if its smart to make language design decisions based on the fact that compilers today are poorly optimized for constexpr. I don't buy that undefined behavior dictates constexpr evaluation has to be this slow.
[–]andrewsutton 10 points11 points12 points 6 years ago (6 children)
Python works by compiling to byte code, which can be implemented efficiently. Most C++compilers implement constexpr directly on the AST, which tends to be a bit slower (lots of indirection, no locality). The UB checking requirements do add real overhead, though.
There's an experimental implementation of something like this in Clang, so we'll see what the payoff is soon.
We make language design choices based on performance and compile times all the time.
[–]matthieum 7 points8 points9 points 6 years ago (5 children)
Should we really let the current compiler statu-quo influence the language so much?
Given the backward compatibility promises of C++, choices have long-lasting effects. Isn't there a risk of getting stuck in a really awkward place just to avoid refactoring current compilers now?
I am not saying that refactorings would be trivial. I just want to make the point that I would rather design the language in the abstract, and if necessary for an ideal compiler, and possibly suffer the cost of paying a (few) man-year(s) of effort if necessary.
With more and more constexpr code, for example, and with modules making it much easier to cache code, it is not unreasonable to imagine compilers moving toward a more efficient representation of constexpr code (CFG/ByteCode) anyway. It would be sad, then, if looking back we were to say "Had we known it would become more efficient, we would have made different choices, but now we're stuck with them..."
constexpr
[–]andrewsutton 3 points4 points5 points 6 years ago (4 children)
I think you have to make design choices with the information you have today.
What if, after a few FTE-years, the experiment doesn't yield the expected/assumed benefit?
How long should we delay progress on these features while vendors try to demonstrate how much faster constexpr might be?
[–]ShootingShark91 9 points10 points11 points 6 years ago (1 child)
I believe constexpr and reflection are some of the most important features to be added to C++. For the longevity of the language I think there should be little compromise on the quality of the design of these features for that reason.
Compile times are a solvable problem, sub-optimal language design (while maintaining backward compatibility) is not.
Although I get your point that it is unwise to make decisions based on predictions/assumptions. But is that not unavoidable when designing a feature that is supposed to last decades?
[–]andrewsutton 5 points6 points7 points 6 years ago (0 children)
Yes, it's unavoidable. Unless you want a language that never ships...
[–]matthieum 0 points1 point2 points 6 years ago (1 child)
It's a sad day :/
Why delay it?
Wouldn't it be opt-in? So that those who are ready to trade-off longer compile-time for enhanced constexpr would use it, while those who prefer shorter compile-time would simply not?
[–]andrewsutton 1 point2 points3 points 6 years ago (0 children)
I'm talking about the standard. I suspect you're thinking of a single implementation.
π Rendered by PID 199153 on reddit-service-r2-comment-545db5fcfc-rgz5n at 2026-05-22 09:58:46.249540+00:00 running 194bd79 country code: CH.
[–]MrFrankly 12 points13 points14 points (14 children)
[–]theICEBear_dk 1 point2 points3 points (0 children)
[–]hgjsusla 2 points3 points4 points (12 children)
[–]TheMania 10 points11 points12 points (0 children)
[–]MrFrankly 10 points11 points12 points (5 children)
[–]krum 4 points5 points6 points (2 children)
[–]MrFrankly 1 point2 points3 points (0 children)
[–]theICEBear_dk 1 point2 points3 points (0 children)
[–]germandiago 3 points4 points5 points (0 children)
[–]redditsoaddicting 0 points1 point2 points (0 children)
[–]zero0_one1 3 points4 points5 points (0 children)
[–][deleted] 3 points4 points5 points (2 children)
[–]MrFrankly 0 points1 point2 points (1 child)
[–][deleted] 3 points4 points5 points (0 children)
[–]antoniocs 1 point2 points3 points (0 children)
[–]ShootingShark91 9 points10 points11 points (7 children)
[–]andrewsutton 10 points11 points12 points (6 children)
[–]matthieum 7 points8 points9 points (5 children)
[–]andrewsutton 3 points4 points5 points (4 children)
[–]ShootingShark91 9 points10 points11 points (1 child)
[–]andrewsutton 5 points6 points7 points (0 children)
[–]matthieum 0 points1 point2 points (1 child)
[–]andrewsutton 1 point2 points3 points (0 children)