Boost logo

Boost :

Subject: Re: [boost] [range][iterator] contiguous iterators
From: Stefan Strasser (strasser_at_[hidden])
Date: 2013-03-19 10:23:39


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<>)

Stefan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk