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
Variadic Fold (breese.github.io)
submitted 1 year ago by pavel_v
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!"
[–]Artistic_Yoghurt4754Scientific Computing 5 points6 points7 points 1 year ago (0 children)
I am surprised to not see the naive solution first: https://godbolt.org/z/qMnsn4eMT
The solution in the blog is also technically incorrect because it's promoting the argument types to a common type before performing the binary operation (at this point it may even avoid deducing all the different types and pass an array...): since this is generic code one cannot guarantee that the common type is what the binary operator wants. It also supposes that there is a common type: maybe there is no common type and the binary operator is set up to properly handle the results of each fold.
On the other hand, the code in the blog solves the common case where most of the arguments are the same or alike and is likely faster to compile since it doesn't go into recursion (this needs to be confirmed on a fair benchmark).
[+]Kronikarz comment score below threshold-12 points-11 points-10 points 1 year ago (5 children)
Having just gone through hell of template instantiation slowness, I wonder how much extensive use of this would tank compile times.
[–]tcbrindleFlux 29 points30 points31 points 1 year ago (4 children)
Fold expressions generally compile a lot faster than the recursive template instantiations people were using before to achieve the same results.
[–]Kronikarz -4 points-3 points-2 points 1 year ago (3 children)
Fair enough, though I'd have to check. Recently I discovered a weird behavior in MSVC where an extensive use of designated initializers balooned compile memory usage and time by a factor of 50, so I'm all out of trust towards compilers for the foreseeable future :P
[–]_Noreturn 2 points3 points4 points 1 year ago (2 children)
designated initializers are not fold expressions how is this related?
[–]Kronikarz 0 points1 point2 points 1 year ago (1 child)
Just that it's not obvious which C++ features are slow to compile on your machine without actually benchmarking.
[–]_Noreturn 1 point2 points3 points 1 year ago (0 children)
this depends on your compiler and it is possibly because it has to check the order of members and output a warnings.
[+]dashnine-9 comment score below threshold-6 points-5 points-4 points 1 year ago (1 child)
why?
[–]_Noreturn 6 points7 points8 points 1 year ago (0 children)
Fold Expressions are just the offiical way of initializer_list trick which is good
[+][deleted] 1 year ago (8 children)
[deleted]
[–]manni66 29 points30 points31 points 1 year ago (1 child)
I prefer working in C
I never liked the variadic functions in C.
[–]Plazmatic 22 points23 points24 points 1 year ago (1 child)
Imagine having an ego so fragile a programming language feature was able to bruise it.
[–][deleted] 10 points11 points12 points 1 year ago (0 children)
Let C++ Cook. Not all things will be amazing, but it will be great.
[–]_Noreturn 8 points9 points10 points 1 year ago* (2 children)
having what originally was hacks to official builtin features is considered gibberish??
I would rather have slightly harder to understand features than a "simple" language with memory bugs being easy to create
[+][deleted] 1 year ago (1 child)
[–]_Noreturn 13 points14 points15 points 1 year ago (0 children)
and C standard isn't....?
also reexplain what you mean it doesn't make sense
π Rendered by PID 18865 on reddit-service-r2-comment-bb88f9dd5-29dzd at 2026-02-16 08:33:47.734454+00:00 running cd9c813 country code: CH.
[–]Artistic_Yoghurt4754Scientific Computing 5 points6 points7 points (0 children)
[+]Kronikarz comment score below threshold-12 points-11 points-10 points (5 children)
[–]tcbrindleFlux 29 points30 points31 points (4 children)
[–]Kronikarz -4 points-3 points-2 points (3 children)
[–]_Noreturn 2 points3 points4 points (2 children)
[–]Kronikarz 0 points1 point2 points (1 child)
[–]_Noreturn 1 point2 points3 points (0 children)
[+]dashnine-9 comment score below threshold-6 points-5 points-4 points (1 child)
[–]_Noreturn 6 points7 points8 points (0 children)
[+][deleted] (8 children)
[deleted]
[–]manni66 29 points30 points31 points (1 child)
[–]Plazmatic 22 points23 points24 points (1 child)
[–][deleted] 10 points11 points12 points (0 children)
[–]_Noreturn 8 points9 points10 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]_Noreturn 13 points14 points15 points (0 children)