Boost logo

Boost :

From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2001-07-25 15:13:14


Hi boosters,

I got into the following situation:

I have a container of foo's, which I do not want to modify. However, I
want to be able to mark them as used, and then iterate over the unused
ones, marking as I go and decide whether to use or not.

My thought was to make a container of iterators into my underlying
container<foo>, and then my object (call it bar) would return a
boost::indirect_iterator_generator<> to the ultimate user. Great,
would save me a ton of headaches.

However, I ran into a snag. The user, having succeeded in using his
foo, would call bar.mark_used(indirect_iterator). And, given only an
indirect_iterator, the object holding the list of iterators would be
unable to figure out which item to remove from its list (I guess it
could do a find itself based on matching addresses of underlying foo's,
but that seems rather suboptimal). So I guess what I'm asking is, is
there any way for an indirect_iterator instance to give one access to
the 'inbetween' iterator it is using (that is, the iterator to the
iterator to the foo)? I didn't see one in the documentation or the
source code (though the source code is thick enough that I can't be
sure I didn't miss it).

Any help? If it's not there, should it be considered for addition to
indirect_iterator_generator? Thinking about it, I am not sure that it
should -- the ultimate user could then get the iterator to the foo, and
maybe undesiredly increment that. But, then I think we need a better
way to do the task that I am trying to do...

On a more petulant note, is there a reason that one has to write

boost::indirect_iterator_generator<BaseIterator>::type;
rather than
boost::indirect_iterator<BaseIterator>
?

I realize that there are no template typedefs, but it seems that one
could just hide the generator machinery as an implementation detail and
add just one more level of inheritance, and you would be done. Since
I'm returning these iterators instead of just using them in a member
function, make_indirect_iterator doesn't really help here.

Thanks,

George Heintzelman
georgeh_at_[hidden]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk