Boost logo

Boost :

Subject: Re: [boost] [iterator] why isn't there a mapped_type iterator adaptor in boost?
From: Neil Groves (neil_at_[hidden])
Date: 2010-05-16 15:47:23

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

Neil Groves

Boost list run by bdawes at, gregod at, cpdaniel at, john at