3 ms·
The standard library may not be the best way to learn C++ for several reasons. 1. The standard library is allowed to do things that you are not allowed to do.
by jbandela1 3y ago
The standard library may not be the best way to learn C++ for several reasons.
1. The standard library is allowed to do things that you are not allowed to do. Because the standard library goes hand in hand with the compiler, it can take advantage of extensions or implementation defined behavior or even what is undefined behavior in the standard.
2. Because it has to be as resilient as possible despite people using macros and naming things, the standard library uses double underscores "__" a lot to name variables. That is not something you should do because those are reserved for the standard library implementer
3. Because the behavior of classes and functions is specified precisely by the standards documents, there is often less commenting that would be normal
4. Because of backwards compatibility, the standard implementation of certain things can be sub-optimal. For example, std::regex is slower than non-standard implementations and may have security issues with untrusted input. Another example is the hash containers unordered_map. The standard kind of forces you into a certain implementation, where others can be much better. The Abseil flat_hash_map containers can be much more efficient than std::unordered_map
This all is not to say the standard library doesn't contain a wealth of information. It does. However, you may need more C++ experience before you can figure out what is a good technique for you to use in your own code, what is suboptimal for you to use, and what is dangerous for you to use in your own code.
If you want a kind of project that is along these lines, I would recommend the following.
1. Implement std::string (but use a different namespace). This will teach you about memory management, constructors, destructors, STL containers and algorithms.
1a. Implement the small string optimization for your class. Make sure you avoid undefined behavior. This will teach you about unions and type punning rules and when you are allowed to cast pointers in C++ without running into undefined behavior and type alias rules.
2. Implement std::tuple. This will teach you a lot of meta-programming techniques.
3. Implement a multi-threaded queue with push and pop. This will teach you about mutexes and condition variables.
3a. Make it lock free. This will teach you about atomics.