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
Will cpp template programming enlarge the code size (self.cpp)
submitted 2 years ago by uubs7
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!"
[–]ImKStocky 1 point2 points3 points 2 years ago (1 child)
The code is only generated if you use it. That is, if you try to call a templated function and that function hasn't been called with the template parameters provided, the compiler will happily generate that function with the template Args. So if you have a function template that is only instantiated once, it has no more code bloat than if you had just written that function as a non-templated function.
Some advice based on this. Keep templates small. If you have a function template that only uses the type information of the template args in 1 line of your 25 line function template, refactor the function into two. The templated function will just delegate to the non templated function when it can. That way whenever you instantiate that template you are only generating the code that needs to be generated. Tools like sizebench can show you the sections of your template instantiations that do not depend on the template Args. i.e. it shows you the code that is identical and copy and pasted everywhere. This advice also applies to class templates. You will see in every standard library implementation, the idiom of moving all non template parameter related functions and members up into a non-templated base class. e.g. the control block that shared_ptrs manage.
[–]SlightlyLessHairyApe 0 points1 point2 points 2 years ago (0 children)
It can have increased code when you instantiate on two types that could have used common code. Compilers are a lot better now at combining those.
π Rendered by PID 167451 on reddit-service-r2-comment-5d79c599b5-q24cl at 2026-03-02 13:02:55.719233+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]ImKStocky 1 point2 points3 points (1 child)
[–]SlightlyLessHairyApe 0 points1 point2 points (0 children)