tags:

views:

48

answers:

1

I have 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.

+2  A: 

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.

Salgar