|
Boost : |
From: brangdon_at_[hidden]
Date: 2001-11-04 16:29:11
In-Reply-To: <B805792F.1D83C%sparent_at_[hidden]>
On Wed, 31 Oct 2001 09:47:30 -0800 Sean Parent (sparent_at_[hidden]) wrote:
> I think you both more or less correct. I don't quite like the choice of
> operations on the range in the above example - I think the idea of
> incrementing a range to mean "advance the beginning" to be a bit
> awkward and using this implementation in practice would be a bit
> cumbersome.
I didn't see anything cumbersome about my example. I think it had the
right logical structure. Similar structures have worked in other
languages, like Java. Perhaps it is really the names you dislike? Even the
name "range" may be misleading. Here is another attempt:
template <typename in_sequence, typename out_iterator>
out_iterator copy( in_sequence src, out_iterator dest ) [
for ( ; !src.at_end(); src.advance())
*dest++ = src.current();
return dest;
}
Just the names have been changed. The idea is to model a data source like
a sequential file. We can get the current item, advance to the next, and
test for no more items. It is not really like a range. Stroustrup called
it an input sequence in C++PL.
> Try this:
>
> template <typename InputRange, typename OutputIterator>
> OutputIterator copy(InputRange src, OutputIterator dst)
> {
> typedef range_t<InputRange> range;
> range input(make_range(src));
> for (range::iterator iter(input.begin()), !input.is_end(iter),
> ++iter)
> { *dst = *iter; }
> return dst;
> }
To me this is cumbersome. It introduces several new types which make the
code more complex, and I don't see that these layers add any value. There
seems to be a lot of overlap between the roles of a range, and a
container.
> Any container or array type can be used to construct a range.
Are you suggesting that we pass a std::vector to copy(), by value? That
sounds expensive. I think we need to extract the range from the vector
before calling copy(). So we have something like:
vector
InputRange<vector>
range_t<InputRange<vector>>
range_t<InputRange<vector>>::iterator
Where-as my example had just:
vector
in_sequence<vector::iterator>
What does your extra complexity buy us?
-- Dave Harris
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk