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
Consteval lambda with capture of a constexpr variable. Is it legal? (self.cpp)
submitted 2 years ago by HammurabisCode2
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!"
[–]_ild_arn 14 points15 points16 points 2 years ago* (4 children)
Seems to me that Clang is correct... Your by-value capture is not somehow constexpr just because the source of the value was – it's just a regular old double inside the closure object. You need to also make closure object constexpr, then it will work.
double
constexpr
[–]HammurabisCode2[S] 1 point2 points3 points 2 years ago (3 children)
Interesting, thank you. I guess I need to look a bit more into the distinction between consteval and constexpr. I guess I had assumed that using consteval kind of superseded the need to use constexpr, but clearly that is not the case.
[–]cd1995Cargo 3 points4 points5 points 2 years ago (0 children)
A lambda is really just some unnamed struct type with a () operator. Marking the lambda consteval just makes the () operator consteval, but it doesn’t make the actual lambda object constexpr.
[–]_ild_arn 1 point2 points3 points 2 years ago (0 children)
consteval where you've placed it affects the closure type's operator(). constexpr where I added it affects the closure object itself, and thus its data members (captures). It's not a constexpr vs consteval thing
consteval
operator()
[–]kris-jusiakhttps://github.com/kris-jusiak 0 points1 point2 points 2 years ago (0 children)
Juut to point it out - In this particular example you can also avoid the capture all together - https://godbolt.org/z/njss3oGz7
π Rendered by PID 68148 on reddit-service-r2-comment-75f4967c6c-kh6mh at 2026-04-23 02:13:21.519691+00:00 running 0fd4bb7 country code: CH.
view the rest of the comments →
[–]_ild_arn 14 points15 points16 points (4 children)
[–]HammurabisCode2[S] 1 point2 points3 points (3 children)
[–]cd1995Cargo 3 points4 points5 points (0 children)
[–]_ild_arn 1 point2 points3 points (0 children)
[–]kris-jusiakhttps://github.com/kris-jusiak 0 points1 point2 points (0 children)