r/cpp • u/funkinaround • May 28 '26
The C++ Standard Library Has Been Walking Itself Back for Fifteen Years
https://hftuniversity.com/post/the-c-standard-library-has-been-walking-itself-back-for-fifteen-years-and-the-receipts-are-public
98
Upvotes
132
u/MFHava WG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 May 28 '26 •
To quote myself from when this was posted in r/programming a few days ago (link: https://www.reddit.com/r/programming/comments/1tm1j7f/comment/onk71io/?context=3):
Author of
copyable_functionhere. This article conflates ABI and API breaks - just like Sandor's post ...Fixing
std::functionwas not something that was prevented by ABI concerns. It would have been an API break that would have rendered vast amounts of code (essentially any use ofconst function) ill-formed (== code no longer compiles).The same is true for several other examples brought up in the linked article... BTW the article contains factual errors like "[...] acknowledging that the standard's mandated block size is too small [...]" ... there is no mandated block size for
deque.64
u/38thTimesACharm May 28 '26
I'm confused. Toward the end, the article seems to be yet another complaint about ABI stability holding the language back. Yet in their list of damning examples, they cite:
auto_ptr,functional, andrandom_shuffle, where a language feature was released, then later superseded by a better one, and the old one was removedthrow,register, and garbage collection, where a language feature was released, then later removed without being replacedfunctionandlock_guard, where a language feature was released, then later superseded by a better one, but the original was kept too for compatibilityregex,vector<bool>, and slow container implementations, where a language feature was released, and for compatibility no improvements are madeWouldn't an ABI break only help in that last case? And if all of the above are damning examples of how not to do language evolution, what options does that leave?
44
u/erichkeane Clang Maintainer(Templates), EWG Chair May 28 '26
The ABI-break arguments are SUPER dumb, and I hate that the committee keeps getting blamed for it.
Implementations CAN break ABI whenever they want, and frankly, do somewhat frequently in controlled ways. IF your implementation 'cared enough' to fix all of the perf issues folks complain about, they are completely able to do so.
However, the committee _IS_ sensitive to the effects of FORCING an ABI break. The last time we did that in a large manner (C++11 `std::string` losing COW), it was almost a decade of dealing with the fallout for the implementations. `std::regex` sucks because implementers don't "care enough" (read, the headache of an ABI break is more than is gained by fixing it), not because the committee has forbidden them from doing so.
So, when an implementer says "IF you make this change, this is going to cost me YEARS of my life, and make everyone's life a bit worse because of it", the committee tends to listen, particularly when the workaround is trivial. Consider scope_guard vs lock_guard: the committee could either have forced library vendors to have two implementations, tons of compiler work arounds for symbol names, revisioning linked names to contain a new modifier, etc.... OR we could choose a different name.
It was an easy decision.
One thing I think the LEWG/folks complaining about ABI SHOULD do however, is start adding permission to do something different in cases where the standard prescribes an implementation. Not sure which we care enough to do about, but if you reduce some of the 'required' behaviors, implementers COULD make the changes, when appropriately motivated.
10
u/wittierframe839 May 29 '26
I don't get why would you compare (unordered_)map to their flat versions, they are a completely different thing with similar interface, anyone saying that one of them is faster than the other is just wrong.
17
u/marsten May 28 '26
std::regexgets a lot of hate but given the headache of C++ dependency management, I think there's a place for low-performance implementations in the standard library. I usestd::regexin one production case to parse a config file at startup, where performance is unimportant.Similar considerations apply to linear algebra. If I need to solve a 10x10 system it's overkill to integrate
eigenor one of the other optimized solvers. Although in this case the standard library doesn't give a low-performance option; you need to roll your own.5
u/max0x7ba https://github.com/max0x7ba May 29 '26 edited May 29 '26
From what textbook does "insertion in the middle of a large container" workload you refer to come from?
Does that textbook not mention that searching or indexing lists by traversing its nodes is rarely a good idea?
Comparing
std::vectorvsstd::listis completely missing the point. These are not alternative/competing containers, rather different tools for different purposes.std::vectorcannot solve problemsstd::listsolves, and vice versa.Your linear scan and the pointer chase means you misuse
std::listand/or made a wrong choice of the container for your elements.std::listis a node-based container with functionality unavailable instd::vector, in principle.Inserting/removing
std::listelements is O(1) and iterators are required for that. You must keep iterators to inserted elements if you want to be able to remove/append/prepend them at arbitrary positions with O(1) complexity.std::list::splicemoves list nodes/elements between containers with O(1) complexity and no memory allocations. List iterators get only invalidated when the referred element is removed. Adding/removing elements while traversing the list cannot corrupt the list.None of that is possible for
std::vector, apart from O(1) complexitypop_back.Boost.Intrusive allows embedding list nodes into a class, so that one object can be an element of multiple lists or other containers. More than that, it provides O(1) conversions from the object to its iterators in the corresponding containers. The class doesn't need to be copyable or movable. It also auto-unlinks the list nodes upon destruction of the object.
«There are only two kinds of languages: the ones people complain about and the ones nobody uses.»
-- Bjarne Stroustrup, The C++ Programming Language
4
u/drbazza May 29 '26
The 'why' is the lack of standardised package manager (and build tooling). If developers could just reach for something that's (emphasis) trivial to install, third party libraries would be thriving even more than now. And the std-lib would be smaller. A golang approach doesn't fit C++.
Suppose we have some feature that's been added (looking at auto_ptr/regex) to the standard, we have to wait three years for the next revision for any significant defect to be corrected, whilst usage drifts to zero, and you end up with (potentially dangerous) code in the std that no-one should be using.
Versus a third party library that can patch a CVE and release the same day.
10
u/SputnikCucumber May 28 '26
Putting aside the fact this article was clearly written by AI. I'm a little unclear what the article is claiming is a problem.
Removing things from a spec is always harder than adding things to a spec. So of course we would expect the bar for deprecation and removal to be higher.
Is the author claiming that C++ is deprecating too much? Or that C++ isn't deprecating enough?
5
u/axilmar May 29 '26
The actual problem is library code sharing, not that the standard library has some problematic parts and the ABI does not get broken.
That the language does not do ABI breaks is the correct approach. New versions of types can always exist with different names. No one prohibits one to write a better regex library, and many people have done so. The issue is how that code is reached, not that the code did not change under the same name.
What c++ needs is to ditch the concept of 'standard library' and adopt an official central repository and a standard code sharing interface.
In that way, better libraries would reach the audiences much faster, not having to wait for a committee to decide what goes in and what goes out.
And, in this global repository, libraries would be tested against compilers, reviewed, benchmarked, etc and the results would be publicly available, allowing the engineers to pick the correct libraries for their project.
2
u/germandiago May 29 '26 edited May 29 '26
Who saw a language that in 28 years does not deprecate or replace things? Bc it looks like national spprts talking bad about things C++ might do but that most languages also do... all languages evolve and do it, from Java to Python woth 2 vs 3 or C# with .NET vs .NET Core. I do not see what the problem is: that we do not get things right at first shot?
What is the article asking for? Many of those things date back to when there were not even C++11 features.
Even in the case of std::function: how was your code before it existed? Worse than after unless you used boost. We found mistakes, we fix them, that is something that can happen, but we only put the eye on the "mistake", not on the service it provided to us for years.
As a historic review it is ok. But as a rant I think it is unfair if you compare it to alternatives. It just happens. What is important is to keep learning from there and evolve the language. This is the price to pay for languages that exist for a while and evolve.
The article mentions at the end: this is why non-std libs are used. Correct!! In which library you can put a design that will serve you permanently (which needs freezing parts of the design here and there for compatibility). In which one? Tell me one: Java, Python, C#, others? This is not even possible. And those users are well-served by outside libraries, especially taking into account that C++ is used in time-sensitive, fast applications. This is not a mistake: it is a problem without solution unless you want to keep breaking the whole world written using standard components.
1
u/NilacTheGrim Jun 24 '26
You will remove
std::functiononly from my cold dead hands. I lovestd::function. It's simple. Elegant. I get the const-correctness arguments but honestly -- if you care about that there's lots of examples of const correctness being wacky anyway in just the C++ core language itself.std::functionis about asconst-correct as shared_ptr (ortype * const ptr = ...)... really.1
u/Charming-Work-2384 May 29 '26
For me the greatest danger is in 3 libraries and hardly anyone to maintain or expand them (Single digit team)
What happens when they are gone? God Forbid...
The reason that many of the implementations live for ages is not hard to fathom...its not wide implementation. Its downright EGO. Sooner the wrong is removed, the worse the wound decays.
Yes C++ is becoming complex by the day... the C++26 code is hardly recognized as C++ code by a person who is familiar with c+11!! ... The Template, lambda etc variant, visit, expected... made the latest C++ code more cryptic. I think even ChatGPT will crash on a obfuscated C++26 code !
-7
u/funkinaround May 28 '26
I think there are clear AI-assisted writing styles in the article, but the topic and general research seems genuine? I am not sure if that violates rule #3.