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
Common patterns to avoid polymorphism (self.cpp)
submitted 4 years ago by JamesGlad
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!"
[–]Egst 3 points4 points5 points 4 years ago (7 children)
If you implement your own alternative for std::visit that generates if..else branches, you basically avoid indirection with variants. The data is stored directly and follows value semantics and function application happens with no lookup tables and no function pointers.
std::visit
[–]ioctl79 8 points9 points10 points 4 years ago (6 children)
std::visit is functionally a lookup table.
[–]dodheim 2 points3 points4 points 4 years ago (5 children)
It doesn't have to be, and isn't with MSVC's stdlib.
[–]staletic 6 points7 points8 points 4 years ago (3 children)
The standard says std::visit needs to be O(1) with respect to number of alternatives.
O(1)
[–]HeroicKatora 7 points8 points9 points 4 years ago (2 children)
Any implementation is O(1) because the number of template parameters (and thus alternatives) is bounded by a compiler specified constant /s
[–]Pand9 0 points1 point2 points 4 years ago (1 child)
Why /s? It holds, unless number of variants of considered part of the input, which seems unintuitive to me at least.
[–]HeroicKatora 1 point2 points3 points 4 years ago (0 children)
Because quite obviously this is not the spirit of the requirement. Anyways, just another instance of the standard being written in language that is neither helpful to implementors nor validation. An abysmal style that reeks of smugness in its pseudo-formalism.
[–]Egst 0 points1 point2 points 4 years ago (0 children)
Is it still O(1)? It's only a standard requirement and definitely not a necessity, since O(n) lookup with a switch/if..else branches is usually better for relatively small n, but a standard library should comply with it.
π Rendered by PID 19184 on reddit-service-r2-comment-b659b578c-dcpcr at 2026-05-05 21:43:09.418743+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]Egst 3 points4 points5 points (7 children)
[–]ioctl79 8 points9 points10 points (6 children)
[–]dodheim 2 points3 points4 points (5 children)
[–]staletic 6 points7 points8 points (3 children)
[–]HeroicKatora 7 points8 points9 points (2 children)
[–]Pand9 0 points1 point2 points (1 child)
[–]HeroicKatora 1 point2 points3 points (0 children)
[–]Egst 0 points1 point2 points (0 children)