Boost logo

Boost :

Subject: Re: [boost] [range][iterator] contiguous iterators
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2013-03-19 11:18:33

On 19-03-2013 15:23, Stefan Strasser wrote:
> Am 19.03.2013 14:07, schrieb Thorsten Ottosen:
>>> going back to my example of database.get, you might wanna use it to load
>>> image data into a large container,
>> No problem here.
> right.
>>> or use it to load 4 byte into an
>>> integer.
>> Hm. How would that work? What concepts do you have in mind? Do yo want
>> to interpret an int as a container of 4 bytes?
> no, not as part of what I'm proposing to be added to Boost.Range. it was
> an example only.
> the point is that there are many algorithms that you don't want to only
> be able to output into containers, as you've suggested using push_back,
> but into anything, using an OutputIterator. like copy().
> but there are cases you can't use a regular OutputIterator for
> efficiency reasons, because the result has to be a bulk call to
> std::memcpy if that's possible, not iterating one by one.
> so instead of writing a generic function:
> template<class OutputIterator> //'char' value type
> void load(OutputIterator);
> you are forced to use
> template<class Container>
> void load(Container &);
> for performance reasons. which you don't want, see above.
> please see my original email for how I'm suggesting to solve this.
> even copy() could benefit from this, e.g.:
> copy(Range const &r,OutputIterator out){
> copy(r,out,category of out);
> }
> copy(Range const &r,OutputIterator out,range_output_iterator_tag){
> *out=r;
> }
> "out" can now copy the whole range at once, using vector.reserve(). or
> sputn() it into a file without buffering. or whetever else.
> (for that, it needs is_contiguous<>)

It appears to me that you can just do that by implementing a wrapper
class that enables you to call boost::push_back. If its too contrieved
to use push_back, we may add a function called write:

template< class OutPutRange, class Rng >
OutPutRange& write( OutPutRange& to, const Rng& from )
{ to.write( from ); return to; }

Anyway, I guess its possible to define an "output range", but it does
not seem desirable stick it into the existing interface for output
iterators, does it?


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