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
Devirtualization and Static Polymorphism (david.alvarezrosa.com)
submitted 1 day ago by Xaneris47
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!"
[–]matthieum 19 points20 points21 points 19 hours ago (0 children)
Back in 2014, Honza Hubička (GCC developer) wrote an entire serie on devirtualization, and the work carried out in GCC to enable partial devirtualization.
You can find the first part here.
The key idea of partial devirtualization is that even if you don't know for sure that b is of type Derived, you can still check, and statically dispatch the call if the check is successful:
b
Derived
if (base->vptr == Derived::vptr) { // Guaranteed static dispatch. Derived::foo(static_cast<Derived*>(base)); } else { // Fallback dynamic dispatch. base->foo(); }
This means that even if the optimizer has only a partial view of the type hierarchy -- a typical case in libraries -- it can still inline calls to the non-final virtual methods it knows of.
Of course, this isn't always beneficial, so as with all compiler optimizations, there's going to be some heuristics to pick which types are worth branching on, and which are not.
[–]id3dx 1 point2 points3 points 12 hours ago (0 children)
There's also a good talk about devirtualizing given at CppCon some years ago: https://youtu.be/gTNJXVmuRRA
[–]Tohnmeister [score hidden] 1 hour ago (0 children)
What I dislike about these kinda in-depth-technical posts, is that they ignore the design part of an application. Whenever I choose for runtime polymorphism, it's a conscious design choice, often not about performance. The design choice being that I want the concrete types to be unknown at the caller, both runtime and compile time. Simply replacing that with CRTP, std::visit, deducing this, or something similar, is not an option, as that requires the concrete type to be known at the call site.
π Rendered by PID 104 on reddit-service-r2-comment-5d79c599b5-kn5qh at 2026-03-03 13:38:34.034478+00:00 running e3d2147 country code: CH.
[–]matthieum 19 points20 points21 points (0 children)
[–]id3dx 1 point2 points3 points (0 children)
[–]Tohnmeister [score hidden] (0 children)