Home

StephQ wrote:

> Thanks for the reply.
> However I got an idea.... what if I use a back_insert_iterator?
> This way only one version can cover everything!

Did you not read my first reply (and others). We've mentioned
std::back_inserter there.

> I can pass a normal iterator if I want to overwrite or a
> back_insert_iterator if I want to append...

Yes, of course - read my first example.

> May a back_insert_iterator become invalid if reallocation happens in a
> vector?

A back_inserter might cause reallocation if the vector exceeds its
capacity.
This may be prevented by reserving in the destination vector.

> Does this means that it's safe to use back_insert_iterator s only with
> lists?

No, back inserters always does push_back, and should not care whether
iterators are invalidated or not. On the other hand, if your functor
stores
iterators while you traverse and pushback, then those may be
invalidated.
(but that is a bad idea anyway)

Werner

previous
next

Re: Pointer vs Reference
Re: C++ An Inline Function Question
Re: Let's Unite Against Jews and Mongrels!
Re: C++ struct wont autocomplete in visual C++
Re: Autogenerate functions (array of lambdas)
Akogo
Fundacja Sloneczko
Fundacja Hobbit
Kidprotect
Nasze Dzieci