开发者

Custom iterator for a class based on two sets

开发者 https://www.devze.com 2022-12-27 18:29 出处:网络
I ha开发者_运维知识库ve a class that contains two sets.They both contain the same key type but have different compare operations.

I ha开发者_运维知识库ve a class that contains two sets. They both contain the same key type but have different compare operations.

I would like to provide an iterator for the class that iterates through the elements of both sets. I want to start with one set, then when I increment an iterator pointing to the last element of the first set, I want to go to the first element of the second set. How do I do this? I would like to preserve the bidirectional iterator semantics of std::set, but if it turns out that implementing a forward iterator is much easier, so be it.

I'm willing to use the Boost Iterator library if that would help.


I implemented a very similar iterator using the boost libraries:

Have a read from here: http://www.boost.org/doc/libs/1_42_0/libs/iterator/doc/iterator_facade.html#a-basic-iterator-using-iterator-facade

For a forward iterator you will need to implement the operator++, to change that to a bidirectional iterator you need to implement operator--.

The implementation is up to you, but all is explained in the documentation.

0

精彩评论

暂无评论...
验证码 换一张
取 消