r/cpp •

Am I the only one that hates C++'s STD library?

[deleted] — view deleted post

0 Upvotes

39 comments sorted by

9

u/UnusualPace679 3d ago

I've encountered at least 10 different ways of handling strings in different libraries and it's a hastle to convert between each of them.

And you want to write yet another library?

2

u/johnnyfedavo 2d ago

Fair enough))

17

u/markt- 3d ago edited 3d ago

With regards to strings, what it sounds like you hate, is that everyone implemented their own string, before C++ (already becoming quite widely used) had effectively standardized on its own. But going on and writing your own is going and repeating the very thing that you appear to dislike, so there’s no point in doing it. The fragmentation that you are witnessing for these types of classes is the result of C++ being a victim of its own early success before the std library existed.

And you are not alone in the frustration that there was no standardization for strings earlier on. But nothing can be done about the past, all we can do is move forward.

As for the apparent duplication of functionality in the standard library, much of that is a consequence of C++ evolving while maintaining backward compatibility. Things like std::print aren’t intended to be yet another way of doing something for the sake of it, but rather a better way of doing something that couldn’t previously be done as conveniently or safely. You don’t have to use every feature the standard library provides. If you want a simpler and more consistent interface for your own projects, there’s nothing wrong with writing a thin abstraction layer over the standard library rather than reimplementing it. That way, you get the interface you want without sacrificing interoperability or having to maintain implementations of things that have already been implemented, tested and optimized extensively.

2

u/johnnyfedavo 2d ago

I agree with you, and I guess if I keep using C++ I need to get used to the backward compatible way of thinking.

35

u/Karr0k 3d ago

Alright gang, whose turn was it to post the xkcd 'standards' link today?

27

u/floatfloatjam 3d ago

You have no idea what you're talking about. This post is effectively gibberish

0

u/johnnyfedavo 2d ago

I'm only an intermediate level programmer so maybe, just listed out my concerns and asked for feedback

2

u/die_liebe 1d ago

Actually, you didn't list any concrete concerns, just a polemic post.

If you don't like modules, that's fine, but they are not part of STL. For the rest, it is a policy of C++ to include all of C, and in general to be backward compatible. I recommend that you don't use the C- features, and always use the most recent option, unless you are dealing with low level or legacy code.

I know only of three ways to deal with strings: std::string, std::string_view, and const char*. Please enlighten me about the other seven.

> Also, would it be crazy to write my own, simpler, version of the STD library for my own projects?

As a programming exercise, it would be very valuable. It would be a humbling experience for sure.

11

u/DragonflyOk9274 3d ago

Sure, there are a lot of parts of the STD library that aren't great. You know what's nice though? The standard library let's me write my own container, provide iterators, and call std::sort on it, std::lower_bound to find the element I want, etc. I don't have to implement my own partition_point for my container!

My data doesn't even need to be contiguous -- I can put them in different pages, or have them use a ring buffer (double ended queue in fixed storage), and as long as I provide the necessary iterators I can get access to a multitude of battle-tested, well defined algorithms with barely any work on my part.

Similarly, I can write an algorithm I want that uses iterators (or ranges!) and not even need to know what data type it will operate on.

5

u/Carl_LaFong 3d ago

Just use only what you find useful and ignore the rest (until you need it). Implementing something yourself is ill-advised, because your code will not handle pitfalls that you haven't encountered or anticipated. It's hard to impelement even very simple functions. This, of course, is due to the complexity of C++ as a language. It's better to use libraries (I believe there are althernatives other than STD and Boost) developed by much more experienced programmers than you.

4

u/m4x-pow3r 3d ago

Yes there are often tons of different ways to do things, but that is by far superior than zero. Recently I had to implement an algorithm in C# where I needed a heap, or what C++ calls priority_queue. Apparently C# didn't have that in the version I had to use, and it only got added recently. I was quite frustrated to have to load an external library for something as basic as this data structure. I think C++ offers a nice balance between offering new library festures and keeping old ones for support. And while there are multiple ways to do things, if your starting a project from scratch, there aren't that many sensible options, e.g. I couldn't think of a reason to use cout over std::print.

4

u/chardan965 2d ago

The standard library is neither perfect nor ideal for everything, but studying it will also give you an absolute masterclass (way more than one, actually) in software design. Many things in it are powerful, reliable, and really really good. You will all but certainly have many mind-expanding experiences studying it, and I mean that in the best way.

You aren't alone in your frustrations; and there are other alternatives available for many tasks (and there have been for decades), but I encourage you to also not "throw the baby out with the bathwater".

10

u/ImNoRickyBalboa 3d ago

What do you mean 'handling strings in different libraries". There's string and string_view, but that's it.

I grant you that string is an overly heavy class, most of it member functions should have been free functions like all the thousands of 'find' functions.

But otherwise, it's fine, stick to the container glasses, mix in other libraries (boost, absl, etc) if you have a need, and move along.

Also no use complaining about std namespaced C functions, it's the compromise needed to keep this weird C compatibility edge.

3

u/ts826848 3d ago

What do you mean 'handling strings in different libraries". There's string and string_view, but that's it.

My guess would be that they're referring to the existence of alternative string types like QString from Qt and cv::String from OpenCV. idk whether 10 different ones is hyperbole or literal, but it wouldn't surprise me that much if OP is working a lot with old libraries.

10

u/manni66 3d ago

Also, would it be crazy to write my own, simpler, version of the STD library for my own projects?

Yes

6

u/johannes1971 2d ago

I hate that it introduced string_view, and in that same version gave us functions that still take const char * arguments. I hate that compiler vendors treat the ABI as set in stone, "because someone out there may have a public interface where they pass a std::regex", but at the same time you cannot actually rely on that because the regex from MSVC is certainly not binary compatible with the one from clang (just an example). I hate that we are treating terminal IO as vitally important, but treating network IO as a contagious disease - in 2026, when almost nobody uses the terminal anymore apart from a handful of IT specialists. I hate that we are getting utterly obscure math functions, but no useful OS abstractions beyond threading and file- and terminal IO. I hate that people treat it as a zero-sum game: that adding a feature they don't need still somehow carries a personal cost to them, and therefore they must fight it. I hate that every feature is designed only for performance, with zero regard to ergonomics (coroutines, random numbers, the whole async debacle, and let's not forget the current proposal for contracts with its ridiculous nesting of namespaces).

But I'm not writing my own.

-1

u/SkoomaDentist Antimodern C++, Embedded, Audio 2d ago

I hate that compiler vendors treat the ABI as set in stone, "because someone out there may have a public interface where they pass a std::regex", but at the same time you cannot actually rely on that because the regex from MSVC is certainly not binary compatible with the one from clang (just an example).

That's because the problem has always been Linux distros and the utterly obsolete dynamic linking model, not anything on Windows side.

8

u/Orangutanion 3d ago

You're not, but that's why other programming languaesg exist. Maybe try Rust or C# or something? It honestly would be a bit crazy to write your own STD library when all these good alternatives exist. C++ has tons of competing standards (like the XKCD skit) so you'd just be adding to that mess.

15

u/-TheWarrior74- 3d ago

rust has 3 types of string with 2 variants of owned and borrowed, 1 for rust strings, 1 for os native strings, 1 for c strings

so here we come to the harrowing concept; the standard library is complicated because programming is fucking complicated

1

u/johnnyfedavo 2d ago

Thanks, I have tried C# and liked it but I'm still not sure about the performance so I think I'll use C++ for demanding jobs.

2

u/FlyingRhenquest 3d ago

Rattle off little libraries that let you address whatever shortcomings you think you're facing at the moment and glue things together with them. The C++ standard library is actually pretty good these days. I rarely have to grab another one. I do have a few I like to have on hand though.

  • A signal/slot library like boost::signals2. Whether I use boost::signals2 or a header only one from elsewhere largely on whether I'm bringing any more of boost in to my project.
  • boost::spirit::x3 for the rare occasions when I need to write a parser.
  • Compile time fixed string library. Severely underrated.
  • Edit: Oh yeah, and reflect-cpp. Can not live without.

I'm also delving into boost asio for asynchronous IO and... stuff, along with nvidia's stdexec library. Actually asio specifically with stdexec. But probably 98% of what I do on a daily basis is just using the standard library. And I'm pretty sure my boss isn't going to let me use stdexec in my day job.

1

u/johnnyfedavo 2d ago

Thank you for writing about reflect-cpp, I never knew about this, didn't even know I could do something like that in C++

1

u/FlyingRhenquest 2d ago

Oh yeah! Serialization in C++ has been a mostly solved problem for about a decade -- you could at least sort of do in in C++17 with the Cereal library, but you had to write a function or two with each of your classes for that to work. Being able to serialize to several text formats and at least a couple of binary ones was really nice, though. Reflect-cpp still has some limitations in C++20/23, but it's a huge improvement. Reflect-cpp with C++26 is magical. As far as I know you still have to build your own compiler if you want to play with that, but I have a project that works with WSL's Debian or Ubuntu quite well. I've been experimenting it since P2996 support dropped in January and it's a game changer. Wish I had more time to experiment with it.

3

u/theblancmange 3d ago

Could try boost as an alternative, but you may find a similar issue there. I take the STL a la carte. I use smart pointers, std::thread and containers/etc but thats about it.

3

u/Anxious-Resist8344 3d ago

Yeah, just you :)

2

u/nicemike40 3d ago

Here’s some catharsis is you want:  https://mcyoung.xyz/2025/07/14/best/

1

u/levodelellis 2d ago

If you want you can DM me for my standard library. I was considering making it public domain

1

u/staletic reddit thinks /u/_bstaletic is a bot 1d ago

Also, would it be crazy to write my own, simpler, version of the STD library for my own projects?

Besides other answers, there are parts of the standard library that you can't replace.

  • std::byte is just an empty enum, except it has "magic" aliasing properties.
  • auto list = {1,2,3} constructs an std::initializer_list.
  • Exceptions/RTTI works with std::type_info.
  • operator<=> returns one of std::strong_order, std::weak_order, or std::partial_order.
  • std::start_lifetime_as can be approximated with std::memcpy and std::launder, except std::start_lifetime_as is not allowed to actually touch storage.
  • std::nullptr_t does not require an include or import.
  • The reflection operator, which which can't be overloaded, returns std::meta::info, a type that can't exist at runtime.
  • Depending on what implementers do about P3861 proposal, std::span<T> and std::string_view will either break ABI (not likely) or become magic types that can not be implemented, in C++26.

1

u/Jakkilip 3d ago

compile times are awful on std library yeah...

1

u/AciusPrime 3d ago

What you’re seeing is the fossilized detritus of a language that took backward compatibility and general-case libraries seriously. Your job is to stick to the relevant stuff and ignore the other stuff. Some of the old stuff is left in there so old programs can keep working. You can ignore it.

The library has two string types that matter: constant strings (const char[]) and mutable strings (std::string). Function parameters need std::string_view, which is not actually a string type, it’s a view type. I have no idea how you got to ten, but you probably got confused about some of the adapters like basic_string or the old-school Unicode support like wstring. There are reasons for these things and they don’t matter. Just trust that they come up in weird corner cases and are part of making a library Actually Generic.

Writing your own is a waste of time and irresponsible in a commercial environment. If you’re just screwing around and writing stuff for your own enjoyment then do what you like, but don’t expect anyone else to take it seriously when you try to share your “std but worse.” Remember the golden rule of C++: only use the stuff that fits your needs. It’s an extremely general language; nobody uses all of it. Those bits you don’t need are there for Somebody Else. Just leave them alone and it will be fine.

1

u/fortsnek274 3d ago edited 3d ago

Modules are a godsend. Eventually. No trash-talking my modules!

But as the std lib has back compat, it's got all the old stuff in it. iostreams, iterator range algorithms, variable templates that do the same thing as the old type traits.

But that won't ever be changed without a C++2.

I've encountered at least 10 different ways of handling strings in different libraries and it's a hastle to convert between each of them.

If the libs have their own string types, that's not the std lib's fault. If they have different encodings, then that's an ongoing problem with C++. Is char UTF-8 or not. Why aren't we using char8_t more.

Also, would it be crazy to write my own, simpler, version of the STD library for my own projects?

It will compile faster, but is it really worth it. You might as well write a new language. Plenty of old cruft there too.

2

u/johnnyfedavo 2d ago

Didn't mean to diss on modules, but I'll just wait until more people use them

1

u/luke727 3d ago

The STL tries to be all things to all users, and different users are going to have different opinions on how things are done. If you don't like it then write your own or use a 3rd party.

1

u/Tringi github.com/tringi 2d ago edited 2d ago

My only critique of STL is overspecification that prevents more optimized implementations. I really don't pass along iterators into containers that mutate while carefully navigating invalidation rules. But that's just me.

Although I would really like standard version of small-buffer-optimized std::vector. I just wrote another minilibrary that almost always processes and returns single item, but there can be more of them, and to keep the code trivial, I pass it/them in std::vector. So usually just one, heap-allocated, item in it, and that feels like unnecessary pesimisation.

0

u/Zen-Ism99 3d ago

Pick a way and stick with it. Problems solved…

-1

u/Moose_bit_my_sister 3d ago

Youre not crazy but first lookup EASTL which is readable and debug-friendly STL reimplementation used in (some) game engines. Personally i only use STL in code i dont really care about (since it doesnt reach production) such as unit tests

0

u/rbmm 3d ago

Possible simply not use std and even crt. Rare choice, but possible 

0

u/[deleted] 3d ago

[deleted] — view deleted comment

1

u/no-sig-available 2d ago

isn't this literally the #1 complaint about the language?

No, the main complaint is all the things that are missing, like networking and graphics. Or the input counterpart of std::print.

So, in addition to being too large, the standard library is also way too small. :-)