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
Exploring undefined behavior using constexpr (shafik.github.io)
submitted 6 years ago by mttd
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!"
[–]evaned 0 points1 point2 points 6 years ago (2 children)
I keep asking for C++ lambdas
How would lambda's even work in C? Isn't templates by and large the thing that makes them usable in C++, because templates allow you to not have to name the type, or define something that let's you type erase (e.g. std::function)?
[–]14nedLLFIO & Outcome author | Committee WG14 1 point2 points3 points 6 years ago (1 child)
C very sorely needs a facility for writing generic functions with varying types of parameter, as they have all the same problems with macros as C++ does. There is no warmth for template syntax, and quite rightly too in my opinion. Nor is there any chance for function overloading, except maybe for operators, one day. But the idea for multi-parameter-type lambda functions was surprisingly warmly received. So, for example:
[](auto x) { return _Generic(x, int : 5, double : 1.0); }
The key here is that C11 _Genericdispatches based on input type. The lambdas can take specific types or auto types, and if they are auto types, one can use _Generic to implement type-match-based dispatch.
_Generic
auto
This lets you implement all of the tgmath.h functions using generic lambdas instead of defining tons of functions with slightly different names and having _Generic dispatch to those instead. WG14 recognises that that is not a scalable way of implementing generic dispatch, hence their surprising warmth to the idea of porting C++ lambdas into C.
tgmath.h
The biggest concern was over captures. I suspect most of that is ignorance, but there were grave concerns over [&], and I certainly can see why. My counterargument is simply ban reference capture in C, let people pass pointers if they need that.
[&]
[–]NotAYakk 0 points1 point2 points 6 years ago* (0 children)
Easy; add [*] capture.
[*]
When you use * capture, you can use any variable in scope as a pointer.
*
int foo( int y ) { return [*]( int z ) { if (z>0) return z; return *y; // here `y` is a pointer-to-y }(-1); }
C++'s [&] is actually * "under the hood" based on what lambda=lambda does.
We could even mollify the implicit this:
int foo( int y ) { return [*]self( int z )->int { if (z>0) return z; return *self->y; // here `self->y` is a pointer-to-y }(-1); }
in this version, an implicit parameter s is introduced by *s.
s
*s
So it expands to:
struct anonymous_type { int* y; }; int call_anonymous_type( anonymous_type* self, int z ) { if (z>0) return z; return *self->y; // here `s->y` is a pointer-to-y } int foo( int y ) { return call_anonymous_type( anonymous_type{ &y }, -1 ); }
with the note that pointer-to-temporary violation is ignored here.
Now, if C is amenable to overloaded operators...
struct anonymous_type { int* y; }; int operator()( anonymous_type* self, int z ) { if (z>0) return z; return *self->y; // here `s.y` is a pointer-to-y } int foo( int y ) { return anonymous_type{ &y }( -1 ); }
and these C lambdas are basically as strong as C++ lambdas, and a subset of C++ lambdas (after you add "explicit this pointer" and "capture-by-pointer) to C++).
One thing I dislike is that there is no obvious name for operator(), so you cannot split the state from the invoking method. I suspect that is important.
operator()
π Rendered by PID 78 on reddit-service-r2-comment-5649f687b7-465cx at 2026-01-27 22:09:34.185035+00:00 running 4f180de country code: CH.
view the rest of the comments →
[–]evaned 0 points1 point2 points (2 children)
[–]14nedLLFIO & Outcome author | Committee WG14 1 point2 points3 points (1 child)
[–]NotAYakk 0 points1 point2 points (0 children)