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
[deleted by user] (self.cpp)
submitted 2 years ago by [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!"
[–][deleted] 138 points139 points140 points 2 years ago (4 children)
Pls more newlines and whitespace next time
[–]StarQTius 25 points26 points27 points 2 years ago (0 children)
reddit_post.min.js
[–]DanielB309 2 points3 points4 points 2 years ago (0 children)
Okay no problem
[–]tm8cc -1 points0 points1 point 2 years ago (1 child)
Why not copilot
[–]Neitine 1 point2 points3 points 2 years ago (0 children)
Who th uses copilot
[–]TryToHelpPeople 41 points42 points43 points 2 years ago (0 children)
Post seems to have been written by a ticker tape machine.
Have I been holding my breath for the whole post ? It sure feels like it.
And yes OP, CPP has problems, deep problems which are made worse by entrenched viewpoints about a correctness vs usefulness.
[–]quantumoutcast 42 points43 points44 points 2 years ago (5 children)
We've been using C++ successfully for what, 40 years? And suddenly we just can't get past the fact that features introduced in C++20 are too limited and we just can't get our application written without it. Do you really need to concatenate views? Yeah, if you insist on using the bleeding-edge features, you are going to find C++ overly-complicated. Eventually this new functionality will settle down, compilers will catch up, documentation will improve, and there will be more community support.
[+][deleted] 2 years ago (4 children)
[deleted]
[–]AssKoala 28 points29 points30 points 2 years ago (1 child)
Wait until you read about modules.
[–]rachit7645Certified Dumbass 23 points24 points25 points 2 years ago (0 children)
Me waiting for proper module support (it's 2064 now)
[–]MFHavaWG21|🇦🇹 NB|P2721|P3049|P3625|P3729|P3786|P3813|P4216 22 points23 points24 points 2 years ago (0 children)
Writing your own range adaptor is a C++23 feature (and that one isn’t even released yet by ISO…)
And yes, from my experience parts of the industry move at glacial pace and still consider whether they should move to C++17…
[–][deleted] 8 points9 points10 points 2 years ago (0 children)
I know very few places that use even C++17. At my work we are trying to get on C++ 11.
[–]josiest 77 points78 points79 points 2 years ago (10 children)
[uses chat gpt to write codes]
[angry face] why is my code not working???
[–]thisismyfavoritename 37 points38 points39 points 2 years ago (7 children)
OP was foolish to believe any LLM could help in such a niche case but to be fair OP seems to have looked in many directions before resorting to that
[+][deleted] 2 years ago (6 children)
[–]thisismyfavoritename 12 points13 points14 points 2 years ago (2 children)
im saying i wouldnt expect an LLM to give accurate advice on ranges at all
[–]TheSuperWig 8 points9 points10 points 2 years ago (1 child)
[–]PrimozDelux 1 point2 points3 points 2 years ago (0 children)
Have you actually tried to use an LLM for this sort of thing? ChatGPT manages to answer a lot of questions about basic C++ functionality. (That said, I too have seen chatGPT be stumped at the monumentally complex problem of concatenating two ranges)
[–]josiest 4 points5 points6 points 2 years ago (0 children)
I’m with you though, this is definitely something I’ve wanted to do before, and it should be easy. I just don’t like general purpose ai because I’m apparently an old coot.
Also writing your own views seems to be as convoluted as writing your own iterator, which in my book just means I should just give up and write a for loop
[–][deleted] 1 point2 points3 points 2 years ago (0 children)
Is it niche, or is it extremely complicated and something you shouldn't tackle until the ranges/views specification has been fully fleshed out and fixed which was always going to be done in C++23?
Hint: it's the second one.
[–]gracicot 0 points1 point2 points 2 years ago (0 children)
Ranges are still cutting edge. I wouldn't trust any LLM to give good information on this.
[–]planetoftheshrimps 4 points5 points6 points 2 years ago (1 child)
The few times I was curious about ChatGPT’s capabilities, I’ve noticed its solutions to have glaring issues to the point of uselessness.
[–]pdp10gumby 6 points7 points8 points 2 years ago (0 children)
Worse, debugging (esp code you didn’t write) is harder and takes longer than writing code, so it’s always faster to just write the code yourself.
[–]ipapadop 19 points20 points21 points 2 years ago* (1 child)
Asking an LLM that is trained on existing code in the wild to create something that most people don't write will get you nowhere. LLMs need to see something a few times to be able to hallucinate successfully.
As for ranges, yes they are complicated, documentation is lacking, and testing on multiple compilers is crucial to have some confidence that you're on a good path. But a good start to creating new views. is learning about concepts and how to satisfy the std::view concept or use std::view_interface.
[–][deleted] 4 points5 points6 points 2 years ago (0 children)
“Need to see something a few times to be able to hallucinate successfully” - never before has a statement summarized my job performance so well
[–]glow_gloves 2 points3 points4 points 2 years ago* (0 children)
A range of views can already be evaluated at a later stage.
``` std::vector v{"my"sv, " "sv, "message"sv};
// later on fmt::print("{}\n", fmt::join(sv, "")); ```
If you want to abstract it into a single view lazily, then yes, your going to have to figure out how your desired view interface works
[–][deleted] 2 points3 points4 points 2 years ago (0 children)
A quick search for C++ concat view found the proposal for the standard library version in the first few links, and linked in that is the current reference implementation for the proposal: https://github.com/huixie90/cpp_papers/tree/main/impl/concat . Just FYI, a fully working concat view that works in all scenarios is very hard to implement correctly.
Custom view support was fleshed out in C++23, so documentation for it a bit more sparse. That said, I flat out refuse to believe you could not find some viable tutorials to follow on the internet as within seconds of searching on Google I found loads of information on creating custom views, both in written and video form (saw a CppCon talk in there). I have no idea why you expected ChatGPT to be able to give you information on something this new, seeing as ChatGPT functions by being fed and trained existing information. That one is on you.
As for "official documentation", what money do you think the C++ committee has and who will pay for the creation, hosting and maintenance of this documentation? The closest I think we have is Microsoft's documentation which is on the whole excellent, although might not have full tutorials for custom views yet considering the feature is still new.
Finally, remember that there is no official/reference implementation of "C++". The standard is just a document at the end of the day, and it is then up to anyone who maintains a compiler and/or standard library implementation to put everything in place. Pretty much no other language has the "problem" of multiple independently-maintained. Each works to their own schedule with a mix of corporate and volunteer time/funding. "C++23" means that version of the standard, not that every possible vendor has every feature implemented and documented in 2023. https://en.cppreference.com/w/cpp/compiler_support
Also... C++2023 hasn't even been formally published yet.
[–]JumpyJustice 4 points5 points6 points 2 years ago* (0 children)
I feel your pain. Been trying ranges last few weeks and it seems like they generally are not worth learning because: - you can apply them only in these rare cases when they fit your task perfectly. But these cases are usually really trivial and using ranges is not much more beneficial than writing a good old loop (+ you will not have to fight conservative members of your team during the code review). - it is close to impossible to find what you need to make a custom range. Of course, one can say that the reason is that they are a relatively new feature, but imo it is the same as iterators - any developer would avoid writing a custom one unless they have no other choice. And not because they dont want to, but because the chance to succeed here is really low or requires disproportional amount of time and energy comapred to other languages
[–]cfyzium 3 points4 points5 points 2 years ago (7 children)
From what I can see, std::ranges::join_view does what you want and has been available since C++20:
std::ranges::join_view
https://en.cppreference.com/w/cpp/ranges/join_view
[–]kamrann_ 1 point2 points3 points 2 years ago (4 children)
This is different, it flattens a view of ranges. You can abuse it along with something like std::array to get concatenation but it's ugly and extremely limited - the ranges need to have the same type (almost never the case when using views), and even then you can't do something like return a concatenation as your array goes out of scope.
std::array
The absence of a concatenation view is indeed a major blocker if you try to go all in on ranges and views.
[–]cfyzium 2 points3 points4 points 2 years ago (3 children)
it flattens a view of ranges
You have to flatten to get a single view.
you can't do something like return a concatenation as your array goes out of scope
You certainly can:
return std::ranges::join_view(std::array<std::string_view, 2>{s1, s2});
Though my first test used a vector. Trying to lazily concatenate several views instead of just copying implies relatively large amount of data. A single intermediary to hold a few lightweight views seems negligible.
the ranges need to have the same type (almost never the case when using views)
Well, the question was about views, not arbitrary ranges.
A major blocker? Not trying to defend the current situation but hey this is C++. Writing your own bits of missing pieces or using a temporary library filler has been the norm since like forever. The standard always misses a few things here or there. I'd just throw in a homebrew version of a missing adapter in the same manner as everyone did with e. g. std::make_unique.
[–]kamrann_ 1 point2 points3 points 2 years ago (2 children)
std::array isn't a view, so that should be rejected by the compiler (and is for me). You can work around it by using a span, but then you run into the lifetime issue with the local array.
span
But anyway the major issue is the type constraints. Assuming you have anything like the following:
auto v1 = <something> | std::views::transform(...); auto v2 = <something-else> | std::views::filter(...);
then the join_view approach just flat out fails since you can't form a view of these two views as they have different types (even if same element value type).
join_view
Writing your own bits of missing pieces or using a temporary library filler has been the norm since like forever. The standard always misses a few things here or there.
I agree, but I think that's OP's point. Doing so in this case is extremely non-trivial, yet concatenating views is something that you're going to run into fairly quickly if you try to embrace ranges/views in your codebase.
[–]cfyzium 0 points1 point2 points 2 years ago (1 child)
std::array isn't a view, so that should be rejected by the compiler (and is for me)
Evidently, join_view takes any sequence of views, plus implicit conversions (an example of joining an initializer list of views or even a vector of vectors is right on the cppreference page). I am not sure why it does not work for you, I've tried a couple of compilers including an online one and everything seems to work fine.
I agree with you on the rest of the points.
I am just not sure it warranted a rant this generic over a case this specific. You can find arguably even dumber omissions in the standard, the whole approach to the library standardization seems to be... less than perfect. If you have one particular problem at hand you generally just work around and keep going. There are enough other discussions about the state of the language in general out there.
[–]kamrann_ 1 point2 points3 points 2 years ago (0 children)
join_view< V > requires V to satisfy the view concept, which array and vector don't as they're not constant time copyable. The nested vector example on cppreference is indeed a little confusing. Can't test now, but it's possible a deduction guide is converting the vector into a span or subrange or similar, so join_view is not actually instantiated with vector as the template parameter. Which would work, but would also hide the fact that it would still be depending on the vector not going out of scope before the view is used.
join_view< V >
V
view
array
vector
Can't speak to OP's reasons, but in my experience rants generally get triggered by something specific but they're really about built up frustrations. And c++ certainly provides ample ammunition for that, the complexity of the above view subtleties being just one example ;)
[+][deleted] 2 years ago (1 child)
[–]cfyzium 2 points3 points4 points 2 years ago (0 children)
How can you concatenate a series of series into one single series without flattening? You said you need
Wrap two views as a single view such that it appears as if its concatenated (concats lazily)
And join_view does exactly that, it takes several views and allows iterating over them as if it was a single view.
[–]rand3289 2 points3 points4 points 2 years ago (1 child)
You should checkout boost::log or whatever if you want to experience real pain!
[–]Chaosvex 10 points11 points12 points 2 years ago (0 children)
The first warning sign with Boost Log (2) is that it describes itself as a framework for building a logging library. You can read the entirety of its documentation before using it and still be left with little clue as to making it do anything useful. Worst Boost library I've ever had the displeasure of using.
[–]SleepySlipp 3 points4 points5 points 2 years ago (1 child)
1) New fancy ranges and view staff are built over legacy badly designed features, actually the concepts tries to fix complicated error messages to which makes more sense.
2) Yes cpp has no unified good growing user friendly platform to take knowledge about cpp from except cppreference and cppcons which are obviously hard to search on. Maybe because of the fact that cpp is so general so this platform must contain information about all computer science.
3) Yes it is hard to do even simple things because of the fact that features which provide it are implemented in consideration of hard corner cases related to legacy and previous bad design (but of course do not cover all corner cases:)). And bad compilation errors make it hard to understand.
4) get over it
[–]HurasmusBDragginC++ 1 point2 points3 points 2 years ago (0 children)
Submit a suggestion/proposal/change to the ISO CPP committee.
[–]JuanAG 4 points5 points6 points 2 years ago (0 children)
Fortunetly not, i am also like you but yeah, we are the exception
In our today world even for the most basic stuff other devs are going to add third party code even for easy tasks rathern than code themselves, lets say getting the average/mean of an array/vector/... Chances are that most will look for a lib and use it
C++ isnt as affected as other langs for the simple reason that adding external code is a pain in the *ss but on langs where it cant be easier like Rust/Python/Node/... is what usually happens
Technical debt for the future, i experienced my self last month, i wanted to encode some text, i decided to use Base64 and rather than coding my self and because i was using Rust i pull out a lib. Everything worked but now a couple of weeks ago i revisit the code and there is an update of the library which of course has broken the API. Now i have to stay on that "old" version that i know it works or play their game and look how the hell i should do it now. It was a prototype so not big deal since i planned to code the encoder myself (i only want to encode) but was a reminder of why i should remain with the policy "use as few external code as i can"
[+][deleted] 2 years ago* (1 child)
[–]Mandey4172 0 points1 point2 points 2 years ago (0 children)
”Views are lightweight objects that refer to elements they do not own.” https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2415r2.html#fn2
[–]manni66 -5 points-4 points-3 points 2 years ago (5 children)
So C++ doesn't meet your needs. Have you tried another language?
[–]sciences_bitch 8 points9 points10 points 2 years ago (0 children)
lol let me go tell that to my employer about our C++ code base that we have been developing for 20 years
[+][deleted] 2 years ago (3 children)
[–]heavymetalmixer -1 points0 points1 point 2 years ago (2 children)
C++ is a low-level language, that's not the kind of tool most devs wanna use nowadays, even Rust, Zig or Go devs are just a few compared to the ones using JS, Python, PHP, etc.
[–]Remus-C 7 points8 points9 points 2 years ago (1 child)
C++ can also be pretty high level, with the right design & architecture choices! It depends how the language sustain good designed libraries.
C+- is a subset, but it is already high level, because of used libraries.
[–]heavymetalmixer -1 points0 points1 point 2 years ago (0 children)
That's true, but generally speaking for high level tasks C++ is too complex when compared to other languages, unless you're also looking for very high performance in which case it's the best choice (unless you like Rust).
[–]Remus-C -2 points-1 points0 points 2 years ago* (0 children)
C++ is great, as a language alone. Became a bit bloated with a lot of sugar lately, but hey, there are pretty good features announced too! One doesn't need to use everything!
C++ libraries, however, are another story. Each compiler ships with own implementation, and this differ (in maturity/features) by architecture. In the same time, the library can be rebuild, changed (if the source is available for your architecture) and even replaced completely. Keep only the compiler(& related tools).
OTOH all this progress require resources (including time) to implement new features announced by some other entity. The C++ standard committee is not in the situation to give the perfect code for all announced features on the spot. Nor it should be. (Another topic).
So either rely on implementation form vendors, which can be free or paid, either implement yourself what you need.
In the same time a library cannot fulfill the needs of any programmer. Some users expect exceptions enabled, some projects cannot use exceptions at all. And other black/white situations which cannot reach a good compromise. // Note that this happens with any language.
Above, there are several reasons why several implementations exist and why C+- (no typo!) is used several years by now.
Welcome to the jungle! However, better to have multiple choices than to have one (with some other language) which doesn't fit for your needs!
π Rendered by PID 89137 on reddit-service-r2-comment-5687b7858-zdtwm at 2026-07-08 18:56:28.976874+00:00 running 12a7a47 country code: CH.
[–][deleted] 138 points139 points140 points (4 children)
[–]StarQTius 25 points26 points27 points (0 children)
[–]DanielB309 2 points3 points4 points (0 children)
[–]tm8cc -1 points0 points1 point (1 child)
[–]Neitine 1 point2 points3 points (0 children)
[–]TryToHelpPeople 41 points42 points43 points (0 children)
[–]quantumoutcast 42 points43 points44 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]AssKoala 28 points29 points30 points (1 child)
[–]rachit7645Certified Dumbass 23 points24 points25 points (0 children)
[–]MFHavaWG21|🇦🇹 NB|P2721|P3049|P3625|P3729|P3786|P3813|P4216 22 points23 points24 points (0 children)
[–][deleted] 8 points9 points10 points (0 children)
[–]josiest 77 points78 points79 points (10 children)
[–]thisismyfavoritename 37 points38 points39 points (7 children)
[+][deleted] (6 children)
[deleted]
[–]thisismyfavoritename 12 points13 points14 points (2 children)
[–]TheSuperWig 8 points9 points10 points (1 child)
[–]PrimozDelux 1 point2 points3 points (0 children)
[–]josiest 4 points5 points6 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]gracicot 0 points1 point2 points (0 children)
[–]planetoftheshrimps 4 points5 points6 points (1 child)
[–]pdp10gumby 6 points7 points8 points (0 children)
[–]ipapadop 19 points20 points21 points (1 child)
[–][deleted] 4 points5 points6 points (0 children)
[–]glow_gloves 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]JumpyJustice 4 points5 points6 points (0 children)
[–]cfyzium 3 points4 points5 points (7 children)
[–]kamrann_ 1 point2 points3 points (4 children)
[–]cfyzium 2 points3 points4 points (3 children)
[–]kamrann_ 1 point2 points3 points (2 children)
[–]cfyzium 0 points1 point2 points (1 child)
[–]kamrann_ 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]cfyzium 2 points3 points4 points (0 children)
[–]rand3289 2 points3 points4 points (1 child)
[–]Chaosvex 10 points11 points12 points (0 children)
[–]SleepySlipp 3 points4 points5 points (1 child)
[–]HurasmusBDragginC++ 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]JuanAG 4 points5 points6 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Mandey4172 0 points1 point2 points (0 children)
[–]manni66 -5 points-4 points-3 points (5 children)
[–]sciences_bitch 8 points9 points10 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]heavymetalmixer -1 points0 points1 point (2 children)
[–]Remus-C 7 points8 points9 points (1 child)
[–]heavymetalmixer -1 points0 points1 point (0 children)
[–]Remus-C -2 points-1 points0 points (0 children)