C++ iterators considered harmful?

后端 未结 13 642
忘了有多久
忘了有多久 2020-12-23 03:42

At the Boost library conference today, Andrei Alexandrescu, author of the book Modern C++ Design and the Loki C++ library, gave a talk titled \"Iterators Must Go\" (video, s

13条回答
  •  星月不相逢
    2020-12-23 03:44

    1. No, they are not bad, they are very clever idea in fact. However, they are not ideal and there is room for improvements in the concept of iterator.

    2. It solves number of real-life problems with iterators. For instance, it's tedious (also error prone) in many cases to query two separate objects, iterators, from a single containers and then pass them as still two separate objects to an algorithm. Why not to pass a single object around? Even std::pair would make for a crude range which is easier to manipulate - one object, not two. Also, it's a good idea to consider a range is an iterator. That's in fact what Andrei suggests. By the way, some of these problems have been already solved by Boost.Range.

    3. I would expect it happened, but it will not be a revolution, rather evolution.

提交回复
热议问题