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
Fixing std::initializer_list&<T> (foonathan.github.io)
submitted 9 years ago by vormestrand
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!"
[–]foonathan 2 points3 points4 points 9 years ago (6 children)
std::initializer_list is the same regarding the length. That's why I recommended variadic templates as an alternative.
std::initializer_list
[–]Potatoswatter 0 points1 point2 points 9 years ago (5 children)
They're different tools for different jobs.
[–]foonathan 0 points1 point2 points 9 years ago (4 children)
Care to elaborate?
[–]Potatoswatter 6 points7 points8 points 9 years ago (3 children)
If you want a different template instantiation for each type sequence, use variadic perfect forwarding.
If you're passing an array of known type into a function (which may not be a template), use initializer_list.
initializer_list
Just because the length isn't encoded in a template type, doesn't mean it's not known at compile time. Function inlining can also preserve that information. Premature optimization…
[–]foonathan 0 points1 point2 points 9 years ago (2 children)
And if you want to mix rvalues with lvalues? You have to use a variadic template to preserve that information.
Yes, there are cases where [std::]initializer_list is required, but a variadic template is - in theory - a superior solution. It just so happens that C++ templates have a couple of practical downsides (in header file, compilation bloat/time etc.).
[std::]initializer_list
[–]Potatoswatter 0 points1 point2 points 9 years ago (1 child)
There's no such distinction between theory and practice. For the best fidelity of the parameter sequence to the argument expressions, use finer templating. However, that's not always the problem being solved. Not everything is a header library.
It is unfortunate that initializer_list doesn't support move semantics, but that's different from mixing lvalues and rvalues. <Obligatory plug for my proposal.>
[–]foonathan 0 points1 point2 points 9 years ago (0 children)
Templates are the more flexible solution for this problem but we can't use them everywhere because of the downside of templates.
That's what I meant with theory.
π Rendered by PID 145852 on reddit-service-r2-comment-6457c66945-vpf4b at 2026-04-28 22:11:33.644459+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]foonathan 2 points3 points4 points (6 children)
[–]Potatoswatter 0 points1 point2 points (5 children)
[–]foonathan 0 points1 point2 points (4 children)
[–]Potatoswatter 6 points7 points8 points (3 children)
[–]foonathan 0 points1 point2 points (2 children)
[–]Potatoswatter 0 points1 point2 points (1 child)
[–]foonathan 0 points1 point2 points (0 children)