
I have a working range implementation, but I find it very difficult to write
an output iterator for use with std::copy, because the updated output iterator is returned by value, and I cannot prove statically that the returned iterator is indeed of the same type as the local one.
As a bit of a workaround,
vector<int> v1 = { 1, 2, 3 }; vector<int> v2; output_iterator<int> o = back_inserter(v2); o = copy(v1.begin(), v2.end(), o);
works, but the operator= is expensive and we lose all the optimization potential from knowing the actual iterator type in the caller as well.
Instead of type erasing the output iterator have you considered type-erasure applied to a 'sink' concept? Alternatively I often find I can use the new algorithm extensions such as boost/range/algorithm_ext/push_back.hpp so that I need not know the output type. I imagine there are many valid use-cases where a type-erased output iterator is a good design choice considering the state of libraries and frameworks at the moment. I thought that the algorithm_ext information might be useful to you now, but if you do need type erasure then perhaps you might like to work on refining a 'Sink' concept. I've got a little bit too much on to investigate and refine this concept in a very short time frame otherwise I would leap to it straight away of course.
Simon
Regards, Neil Groves