Chaining iterators for C++

前端 未结 7 2060
野性不改
野性不改 2020-12-01 12:24

Python\'s itertools implement a chain iterator which essentially concatenates a number of different iterators to provide everything from single iterator.

Is there so

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 12:48

    In C++, an iterator usually doesn't makes sense outside of a context of the begin and end of a range. The iterator itself doesn't know where the start and the end are. So in order to do something like this, you instead need to chain together ranges of iterators - range is a (start, end) pair of iterators.

    Takes a look at the boost::range documentation. It may provide tools for constructing a chain of ranges. The one difference is that they will have to be the same type and return the same type of iterator. It may further be possible to make this further generic to chain together different types of ranges with something like any_iterator, but maybe not.

提交回复
热议问题