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

前端 未结 3 1507
一整个雨季
一整个雨季 2021-01-01 09:01

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

W

3条回答
  •  悲哀的现实
    2021-01-01 09:49

    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 . 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.

提交回复
热议问题