
On 10/26/06, Jason Hise <0xchaos@gmail.com> wrote:
Does boost provide any sort of iterator adapter which can be used as a forward iterator through a collection, but which will act like an output iterator upon reaching the end and push back new values? I am looking for something which will allow me to build a collection as though I was using an output iterator, but will also allow me to save copies of the current iterator so that I can modify the values they point to later.
If there isn't, should I roll my own, or is there a better way to do what I want?
Why don't you simply clear the collection first and use std::back_inserter? I suppose if there are more elements in the container than you write to this iterator, you'd want the remaining elements unaffected.
If I do roll my own, would people be interested in seeing it developed into a boost library?
It doesn't seem that such an iterator would be used nearly often enough to warrant inclusion into boost. People generally either need a std::back_inserter or simply the container's forward iterator, not a combination of the two. Perhaps if you could provide several use cases, this iterator would seem more valuable and not an iterator which is used only in your specific project.
Sidenote: This iterator adapter would require push_back to not invalidate existing iterators (other than end). Therefore, a special iterator might need to be specified when wrapping certain collections. For instance, random access containers (vector and deque) would probably need iterators that stored an integer index and a pointer to the container, because push_back would be likely to result in memory reallocations. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Kevin Spinar