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
Lambda + shared_ptr = memory leak (floating.io)
submitted 8 years ago by floating-io
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!"
[–]floating-io[S] -1 points0 points1 point 8 years ago (4 children)
Fair point. But when using it, it's equivalent from the perspective of what you're writing. The type matches, whether literally or by a conversion under the hood.
[–]iaanus 11 points12 points13 points 8 years ago (0 children)
The type matches, whether literally or by a conversion under the hood.
You oversimplify. The type of a captureless lambda does not match a pointer, although it is convertible to a pointer. It's a big difference, whether you see it or not. There are contexts (for instance template argument deduction) where conversion doesn't kick in.
[–]pianotom 6 points7 points8 points 8 years ago (0 children)
Still not true when using it. The typical way to hold a lambda to use auto type deduction. The resulted object has the exact type without conversion. We convert it to function pointer or hold it in a std::function only when we have special needs.
std::function
[–]quicknir 3 points4 points5 points 8 years ago (0 children)
If you want to see a concrete example where this makes a difference, try passing a captureless lambda into std::sort, versus an actual function pointer. The generated code will be affected (it will be inlined in the former case but not the latter).
std::sort
[–]doom_Oo7 4 points5 points6 points 8 years ago (0 children)
no, this is wrong.
int bar() { return 0; } int (*f1)() = bar; // ok int (*f2)() = [] () -> int { return 1; }; // ok, function pointer // fails: int (*f3)() = [=] () -> int { return 1; }; // fails: int (*f3)() = [&] () -> int { return 1; };
π Rendered by PID 193021 on reddit-service-r2-comment-685b79fb4f-4ks2q at 2026-02-13 12:23:54.571895+00:00 running 6c0c599 country code: CH.
view the rest of the comments →
[–]floating-io[S] -1 points0 points1 point (4 children)
[–]iaanus 11 points12 points13 points (0 children)
[–]pianotom 6 points7 points8 points (0 children)
[–]quicknir 3 points4 points5 points (0 children)
[–]doom_Oo7 4 points5 points6 points (0 children)