r/cpp • • 6h ago

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

I've been using C++ for a couple years and I can't stand the standard library anymore. To me it's a mess of headers and classes. It's jammed with repeating features but in different formats, such as std::print, modules, and other stuff from C that are just in the C++ format. Don't get me started on strings, 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. Am I the only one that hates it? If so please correct me and tell me on how to properly love it.

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

0 Upvotes

24 comments sorted by

25

u/Karr0k 6h ago

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

7

u/ImNoRickyBalboa 6h 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.

•

u/ts826848 1h 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.

5

u/markt- 6h ago edited 6h 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.

11

u/Orangutanion 6h 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.

•

u/-TheWarrior74- 26m 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

4

u/theblancmange 6h 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.

13

u/floatfloatjam 6h ago

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

2

u/fortsnek274 6h ago edited 6h 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/Carl_LaFong 6h 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.

2

u/DragonflyOk9274 4h 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.

3

u/manni66 5h ago

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

Yes

2

u/Jakkilip 6h ago

compile times are awful on std library yeah...

2

u/nicemike40 6h ago

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

1

u/rbmm 6h ago

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

1

u/m4x-pow3r 6h 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.

1

u/luke727 5h 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.

•

u/FlyingRhenquest 3h 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.

•

u/UnusualPace679 2h 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?

1

u/Anxious-Resist8344 6h ago

Yeah, just you :)

-1

u/Noah18923 6h ago

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

0

u/Moose_bit_my_sister 6h 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/AciusPrime 6h 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/Zen-Ism99 6h ago

Pick a way and stick with it. Problems solved…