
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? If I do roll my own, would people be interested in seeing it developed into a boost library? 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.

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

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.
I assumed that needing to modify a value found earlier in a stream based on a value found later in a stream would not be such an unusual thing. Perhaps I was wrong. Is there a better way to approach this problem? I would prefer not to have to flag the values as I encounter them and then iterate over the entire container again to find them. My use case specifically is for an assembler, where I want to output a sequence of byte codes, but remember certain locations which are jump commands so that I can fill in their jump addresses as I encounter their corresponding labels.

"Jason Hise" <0xchaos@gmail.com> writes:
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.
push_back on deque does not invalidate any iterators. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (3)
-
David Abrahams
-
Jason Hise
-
Kevin Spinar