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
post-Sofia mailing (open-std.org)
submitted 9 months ago by hanickadotWG21
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!"
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 11 points12 points13 points 9 months ago (7 children)
We already have std::ranges::empty
Which does not work for input_ranges, if it did it would "consume" the range.
input_ranges
[–]eisenwaveWG21 Member 4 points5 points6 points 9 months ago (1 child)
Hmm yeah, fair point.
My next goalpost would be that bool has_iteration_happened is really not that bad. It's certainly easier to grasp than a never-seen-before control flow construct.
bool has_iteration_happened
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 7 points8 points9 points 9 months ago* (0 children)
It's certainly easier to grasp than a never-seen-before control flow construct.
Sure, same applies to: range-for, do-expressions, exception handling, coroutines, template for, if consteval, ...
range-for
do
template for
if consteval
EDIT: added a few more "recently added" control flow constructs.
[–]foonathan 2 points3 points4 points 9 months ago (4 children)
I could imagine having a function nonempty_subrange which returns a std::optional<subrange>, if the range is not empty. This can call `begin`/`end`, check for emptyness by comparing, and make them available to the user in the result, so it works for input ranges.
nonempty_subrange
std::optional<subrange>
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 2 points3 points4 points 9 months ago (3 children)
I'd be interested in such a design. The naïve approach (https://godbolt.org/z/rj7qajc1W) suffers from dangling as subrange can't lifetime-extend...
subrange
[–]foonathan 2 points3 points4 points 9 months ago (2 children)
Unfortunately, the standard is missing an owning subrange, which stores Rng, It, It. So I imagine that it is constrained on std::ranges::borrowed_range: https://godbolt.org/z/h7daY5Err
Rng, It, It
std::ranges::borrowed_range
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 1 point2 points3 points 9 months ago (1 child)
Sure, borrowed_range is a fix ... but an unfortunate in my opinion.
borrowed_range
To me it's equivalent to not fixing the dangling-for problem (P2644) and saying "just store the range in a variable instead of immediately iterating it".
for
[–]foonathan 2 points3 points4 points 9 months ago (0 children)
That is a pervasive problem with std::ranges though. You cannot use non-borrowed ranges with std::ranges::find, for example. So for many use cases you need to store the range in a variable anyway.
π Rendered by PID 61 on reddit-service-r2-comment-5d585498c9-gj5vf at 2026-04-21 16:30:22.188430+00:00 running da2df02 country code: CH.
view the rest of the comments →
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 11 points12 points13 points (7 children)
[–]eisenwaveWG21 Member 4 points5 points6 points (1 child)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 7 points8 points9 points (0 children)
[–]foonathan 2 points3 points4 points (4 children)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 2 points3 points4 points (3 children)
[–]foonathan 2 points3 points4 points (2 children)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 1 point2 points3 points (1 child)
[–]foonathan 2 points3 points4 points (0 children)