C++ iterators considered harmful?

后端 未结 13 559
忘了有多久
忘了有多久 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:53

    The only argument I can see from that presentation is the inability to define ranges, and the c++0x "Range for statement" proposal seems to eliminate that problem to some extent anyway. maybe it shouldn't be an argument about if iterators should / shouldn't be used at all, but more what situations should / shouldn't they be used for?

    0 讨论(0)
  • 2020-12-23 03:54

    Like any API or function, if misused can create many problems of identification difficult. Iterators have used in many projects, but always maintaining the necessary care required according to their characteristics. Its use should be preceded by a good understanding of their limitations. Iterators can be very useful if user properly.
    This questions are related :
    Is there any way to check if an iterator is valid?
    Should I prefer iterators over const_iterators?

    0 讨论(0)
  • 2020-12-23 04:01

    I think C++ implementors will have their hands full producing full working support for C++0x, without implementing new, non-standard paradigms.

    0 讨论(0)
  • 2020-12-23 04:04

    I think we should use ranges next to iterators, i.e. we should choose the evolution way, not revolution way.

    0 讨论(0)
  • 2020-12-23 04:07

    C++0x is already making the first steps:

    • rvalue references solve some problems with treating containers as ranges
    • ranges have been added to the core library, including range concepts

    Transitioning to ranges without losing any iterator functionality (think of all the combinations of iterator categories, const-ness and rvalue-ness) is hard, especially if you try to factor in infinite and mutable ranges.

    0 讨论(0)
  • 2020-12-23 04:08

    I agree with him that iterators are mostly inferior to ranges, and I don't know if 'something better' will get picked up.

    "The good is the enemy of the best" is strongly at play here, as it usually is. Iterators are useful and firmly entrenched, so it's hard to know if something better like ranges can supplant them in a reasonable amount of time.

    0 讨论(0)
提交回复
热议问题