C++ – Why STL implementation is so unreadable? How C++ could have been improved here


For instance why does most members in STL implementation have _M_ or _ or __ prefix?
Why there is so much boilerplate code ?

What features C++ is lacking that would allow make vector (for instance) implementation clear and more concise?

Best Solution

Implementations use names starting with an underscore followed by an uppercase letter or two underscores to avoid conflicts with user-defined macros. Such names are reserved in C++. For example, one could define a macro called Type and then #include <vector>. If vector implementations used Type as a template parameter name, it would break. However, one is not allowed to define macros called _Type (or __type, type__ etc.). Therefore, vector can safely use such names.