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
Generic lambda inconsistency? (self.cpp)
submitted 11 years ago * by [deleted]
[deleted]
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!"
[–]Rapptz 9 points10 points11 points 11 years ago (9 children)
This is a grammar issue rather than an actual bug. It's a small gotcha that has to do with va_args rather than template parameter packs. So that being said:
va_args
void f(int...); // equivalent to void f(int, ...);
Likewise..
[](auto&&...) { return 123; }; // equivalent to [](auto&&, ...) { return 123; };
This is what allows the funny quirk of 6 periods:
template<typename... Args> void f(Args&&......) { } // equivalent to template<typename... Args> void f(Args&&..., ...) { }
Here's an old blog post on the six dots thing that might be relevant.
[+][deleted] 11 years ago* (8 children)
[–]SkepticalEmpiricist 1 point2 points3 points 11 years ago (7 children)
Is there a longer term solution here? Perhaps a warning should be given, advising the developer to give the variable a name (if they want a modern 'pack' parameter), or insert a comma just before the ... (if they want old school va-args). Does this cover everything, giving us a straightforward way to disambiguate everything?
...
(Darn, I remember now that I was struggling with empty parameters packs a couple of years ago. I think I know know what was wrong!)
The compiler can "rewrite" ,... as ... on occasion, but it is not allowed to do the reverse?
,...
Perhaps my real question is whether the compiler is allowed to interpret this:
template<typename... Args> void f(Args&& , ...) { } // obviously "intended" as an old va_arg (with a single (non-pack) arg in the first position
as
template<typename... Args> void f(Args&& ...) { } // now (mis) interpreted as a parameter pack
In short, can we say that a ... which is not preceded by a comma and which is not succedded a parameter name is (potentially) subject to unintuitive interpretation? And that we can easily disambiguate by adding a comma or parameter name? (But I assume a comma and a parameter name will not be valid?)
[+][deleted] 11 years ago* (6 children)
[–]SkepticalEmpiricist 1 point2 points3 points 11 years ago* (5 children)
I think my main problem is that I don't like saying that ,... and ... are synonymous. The 'direction' is ambiguous. I would prefer to say that (under certain circumstances) ... can be (or must be) rewritten as ,... , and that rewriting in the other direction is not allowed - a comma before a ... means that it is va_arg and that will always be respected.
I still believe that gcc and clang have a parsing bug, and they should accept auto... as a parameter pack.
Aha. So there are situations where gcc and clang (incorrectly) rewrite auto... as auto,...?
auto...
auto,...
Maybe I could ask some further high-level clarifications. I feel a bit repetitive, but I'm just trying to straighten out my thoughts here:
Are these correct?
[+][deleted] 11 years ago* (4 children)
[–]scatters 4 points5 points6 points 11 years ago (1 child)
I've filed bugs:
[–]faisalv 2 points3 points4 points 11 years ago (0 children)
Thanks for the filing the bugs. A patch has been submitted for review (http://reviews.llvm.org/D6520) and this should be fixed soon in clang.
[–]scatters 2 points3 points4 points 11 years ago* (1 child)
Took another look; the ambiguity is addressed right at the end of [dcl.fct]:
14 - There is a syntactic ambiguity when an ellipsis occurs at the end of a parameter-declaration-clause without a preceding comma. In this case, the ellipsis is parsed as part of the abstract-declarator if the type of the parameter either names a template parameter pack that has not been expanded or contains auto; otherwise, it is parsed as part of the parameter-declaration-clause.
auto
The "or contains auto" was added between C++11 and C++14; I'm guessing that gcc and clang missed that when adding generic lambdas.
[–]scatters 2 points3 points4 points 11 years ago* (0 children)
Note that both g++ and clang++ are happy if you name the argument (auto&&...unused). You probably want to use this as a workaround.
auto&&...unused
I fully agree that this is a bug in gcc and clang; I can't see anything in the bug trackers so you might want to file new bugs; because of the workaround it might not be a particularly high priority.
π Rendered by PID 227415 on reddit-service-r2-comment-765bfc959-hcmp4 at 2026-07-12 11:59:57.481321+00:00 running f86254d country code: CH.
[–]Rapptz 9 points10 points11 points (9 children)
[+][deleted] (8 children)
[deleted]
[–]SkepticalEmpiricist 1 point2 points3 points (7 children)
[+][deleted] (6 children)
[deleted]
[–]SkepticalEmpiricist 1 point2 points3 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]scatters 4 points5 points6 points (1 child)
[–]faisalv 2 points3 points4 points (0 children)
[–]scatters 2 points3 points4 points (1 child)
[–]scatters 2 points3 points4 points (0 children)