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

前端 未结 3 1510
一整个雨季
一整个雨季 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:34

    Lots of STL implementations also include checking for debug builds, such as verifying that two iterators are from the same container when comparing them, and watching for iterators going out of bounds. This involves fairly complex code to track the container and validity of every iterator created, but is invaluable for finding bugs. This code is also all interwoven with the standard release code with #ifdefs - even in the STL algorithms. So it's never going to be as clear as their most basic operation. Sites like this one show the most basic functionality of STL algorithms, stating their functionality is "equivalent to" the code they show. You won't see that in your header files though.

提交回复
热议问题