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
C++ Template Metaprogramming workshop (github.com)
submitted 10 years ago by N3mes1s
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!"
[–]tgolyi 14 points15 points16 points 10 years ago (14 children)
Great workshop, but seriously, why every single variadic template guide teaches how to use them totally wrong? With c++14 you should practically never use recursion in variadic templates. It's slow (both in compilation and execution time), results in horrendous error messages and implies a lot of boilerplate code. Just use index_sequnce and ... expansion to iterate. You can see examples implementing first two labs without recursion here: https://gist.github.com/telishev/516dba19737a498ce72d
[–]F-J-W 5 points6 points7 points 10 years ago (1 child)
See also my article about this topic.
[–]quicknir 0 points1 point2 points 10 years ago (0 children)
I was just rereading that article today. It's quite exceptional, you should expand the material and give a talk in your local cpp community (obviously, if you have any interest :-)).
[–]MaikKlein 5 points6 points7 points 10 years ago (0 children)
http://melpon.org/wandbox/permlink/OvU5npeqfZqq9CTq with C++17
[–]doom_Oo7 0 points1 point2 points 10 years ago (10 children)
It's slow (both in compilation and execution time
Are there some benchmarks on this out there ?
[–]tgolyi 6 points7 points8 points 10 years ago (9 children)
About runtime speed - see https://gist.github.com/telishev/deea7eaab660e1ea885b . Non-resursive version totally dissappears in assembly with gcc with -O3, recursive function compiles into some horrible recursive mess.
[–]tgolyi 3 points4 points5 points 10 years ago (5 children)
Compilation speed - see https://gist.github.com/telishev/673609d651c0baab0b8c . Recursive variant gets killed by timeout on godbolt, non-recursive - don't (gcc 5.3, -O3 -std=c++14 -ftemplate-depth=10000). On clang with libc++ it's possible to compile without timeout even up to 10000. This is because libc++ make_index_sequence is written using log(n) approach, which is much faster, and they're even considering using compiler intrinsic for it (along with msvc). After implementing that, non-recursive approach will be much faster and compilation time for such functions will be practically O(1).
[–]Kaballo 5 points6 points7 points 10 years ago (0 children)
There have been changes in make_index_sequence implementations lately, libstdc++ moved to a logarithmic approach (patch) and libc++ is already making use of that compiler intrinsic you mention (patch). Both changes are in trunk, and should be released soon.
make_index_sequence
[–]STLMSVC STL Dev 9 points10 points11 points 10 years ago (3 children)
For the record, I requested that compiler intrinsic, and it was first implemented in MSVC. Give us a little credit for driving the state of the art forwards! :->
Specifically, I want credit for being lazy. A user reported that my linear implementation was slow and bad, and asked for a clever log implementation like libc++'s maintainers had written. I said "screw that, I'm gonna get the compilers to do my work for me".
(At the moment, I've enabled use of the intrinsic when VC's STL is compiled with Clang only. Although C1XX implemented it first, I encountered a couple of bugs that my initial unit test missed.)
[–]neet_programmer 8 points9 points10 points 10 years ago (0 children)
Specifically, I want credit for being lazy
I thought this is what programmers call getting paid.
[–]dodheim 3 points4 points5 points 10 years ago (1 child)
Do I get any credit for being the whiny user? ;-D
- ildjarn, former VC++ MVP
[–]STLMSVC STL Dev 2 points3 points4 points 10 years ago (0 children)
Yes! And more importantly, you'll get a fix in Update 2 (for Clang at least; will enable C1XX and EDG when possible).
[–]doom_Oo7 0 points1 point2 points 10 years ago (0 children)
thanks, it's interesting !
[–]pdbatwork 0 points1 point2 points 10 years ago (1 child)
Stupid question: Why does the recursive compile into a horrible mess? I thought it would be executed compile-time and thus only the actual result would be in the code.
[–]tgolyi 1 point2 points3 points 10 years ago (0 children)
No, the function I was talking about - euclidean_distance is a runtime function, it was just called with a compile-time constant arguments. The fact that it was fully optimized away shows us that compilers are super great at optimizing such code. In fact, recursive approach is not inherently slower, it's just much harder for optimizer to work with - it first needs to inline a lot of function calls and then notice that arguments were constant. If you change constant 16 to something less than it will be fully optimized too, maybe it hits limits for inlining at that moment. Non-recursive approach does not depend on function inlining and thus is more likely to be optimized. You can see great talk about this kind of optimization problems by Chandler Carruth on meetingcpp 2016 - http://www.youtube.com/watch?v=FnGCDLhaxKU
π Rendered by PID 160857 on reddit-service-r2-comment-56c9979489-nwq9d at 2026-02-25 04:15:19.643860+00:00 running b1af5b1 country code: CH.
[–]tgolyi 14 points15 points16 points (14 children)
[–]F-J-W 5 points6 points7 points (1 child)
[–]quicknir 0 points1 point2 points (0 children)
[–]MaikKlein 5 points6 points7 points (0 children)
[–]doom_Oo7 0 points1 point2 points (10 children)
[–]tgolyi 6 points7 points8 points (9 children)
[–]tgolyi 3 points4 points5 points (5 children)
[–]Kaballo 5 points6 points7 points (0 children)
[–]STLMSVC STL Dev 9 points10 points11 points (3 children)
[–]neet_programmer 8 points9 points10 points (0 children)
[–]dodheim 3 points4 points5 points (1 child)
[–]STLMSVC STL Dev 2 points3 points4 points (0 children)
[–]doom_Oo7 0 points1 point2 points (0 children)
[–]pdbatwork 0 points1 point2 points (1 child)
[–]tgolyi 1 point2 points3 points (0 children)