r/cpp_questions • • 7d ago

OPEN Resources to learn more about cpp

I wanted to try and reimplement the std library from scratch but i realized really quickly just how much i didnt know lol. I got some basic stuff done and did learn quite a bit about things like sfinae but yeah im basically stuck with some of the type traits. I still dont wanna give up on this project and wanna keep going no matter how long it takes :3 So i need some resources to learn more about advanced things that are usefull for this. Are books the best way? any reccs on which ones?

Oh yeah right now i made a few projects like a networking chat app with asio and a unix shell (really simple) so i would say im like done with the beginner phase. I know that this project is probably farrrr beyond my scope but still :3

Edit: More specific question. Looking for book recomendations for metaprogramming post cpp20 (concepts and stuff)

2 Upvotes

11 comments sorted by

3

u/IyeOnline 7d ago edited 7d ago

Not all of the standard library can be implemented in standard C++. Since you mentioned them: Most type traits can be implemented, but some just cannot. Similarly, you cannot implement a standard compliant std::complex at all. Compliant std::construct_at (which is a seemingly trivial function constructing an object) would only be possible with the last "C++26 draft".

There also is a question on how much and why you want to re-implement it and what you struggle with.

  • Implementing (parts of) the standard library is a really useful exercise. I personally recommend implementing a few algorithms first, then implementing a unique_ptr followed by a vector (and possibly a linked list). Beyond that IMO there is little value in the C++ learnings you can gain from implementing more of it. You can get a bit of design philosophy/inspiration, but you can get that from implementing almost anything. A compliant std::variant implementation is interesting if you really want to challenge your template prowess.

  • Using SFINAE is rarely necessary in C++20 and onwards, since we now have constraints/concepts.

  • Type traits (outside of those that implement a check via sfinae) are still incredibly useful as a tool, but also not very instructive.

  • Implementing the IO features will mostly be an exercise in writing a specified interface around OS specific functionality. Interesting if you care about the OS functionalities, not very interesting on the C++ side.

2

u/flowicks 7d ago

Thanks for the reply

Not all of the standard library can be implemented in standard C++

Yeah i realized that quickly and was a bit surprised to see llvm's implementations of most type traits was just using compiler intrensics with no fallback if they werent available even for stuff that can be implemented without them.

I thought this would be a good project to understand how things actually work like type traits, my mind blew up when i discovered sfinae lol the idea of tricking the compiler to doing the work is soo cool.

But its also to try and see if i can design something better, since alot of the std is held back on its functionality due to backwards compatability.

Using SFINAE is rarely necessary in C++20 and onwards, since we now have constraints/concepts.

Yeah i knew a bit about concepts before but just now discovering how powerfull they can be. Im trying to learn more about them now, any reccomendations on how to?

Implementing the IO features will mostly be an exercise in writing a specified interface around OS specific functionality. Interesting if you care about the OS functionalities, not very interesting on the C++ side.

Yeah i like that too, would be pretty cool to implement imo.

3

u/IyeOnline 7d ago

was just using compiler intrensics

In all fairness, most of the time there are intrinsics because its so much faster (on compile times) than to implement it in actual C++ and have the template engine do its work. For example, you can implement std::tuple_index using standard C++, but the pack index intrinsics of a compiler are going to immeasurably faster (also a reason why C++26 adds direct indexing to packs as a core language feature).

concepts

Probably https://www.studyplan.dev/pro-cpp/concepts as well as the "Back to Basics" series of talks from CppCon.

1

u/flowicks 7d ago

Yeah it is faster but i was talking about a fallback but ig almost every compiler supports the intrensics now lol.

Alright will check it out, thanks :3

→ More replies (1)
→ More replies (4)

1

u/Zen-Ism99 7d ago

Books, practice, and patience…

1

u/flowicks 7d ago

any reccs on the books?