Boost logo

Boost :

Subject: Re: [boost] [range] RFC: span(iterator, size)
From: TONGARI J (tongari95_at_[hidden])
Date: 2013-10-29 21:38:02


Hi Evgeny,

2013/10/30 Evgeny Panasyuk <evgeny.panasyuk_at_[hidden]>

> 29.10.2013 19:54, TONGARI J:
>
> I want to query if there's any interest in such a utility:
>>
>> span(iterator, size) : iterator_range
>>
>
> That reminds me CountedRanges from STL: http://www.youtube.com/watch?**
> v=dUEA8fHx0r0&t=35m14s<http://www.youtube.com/watch?v=dUEA8fHx0r0&t=35m14s>

Thanks for the link,I'll take a look later.

> which simply returns iterator_range(it, it + size) for
>> RandomAccessIterator;
>> for others modeling ForwardIterator, a special iterator adaptor, say,
>> counted_iterator is used, so we don't have to advance it just for getting
>> the end iterator.
>>
>
> What type of underlying iterator you plan to use, let say for
> ForwardIterator?
>

So called 'counted_iterator', same category as the wrapped one.

It looks like this type will contain not just iterator, and *efficient*
> implementation is not clear for me.
>

The states are:

    iterator it;
    std::size_t count;

For comparison, only count is compared;
dereference is simply *it;
increment both it & count;

So the code below:

    for (auto val : span(it, n)) {...}

Is equivalent to:

    for (std::size_t i = 0; i != n, ++i, ++it) {...}

> Just imagine case where next(end(span(first, n))) is legal, like when
> original range has more than n elements. What end(span(first, n)) would
> have internally, which state?

 it = first; count = n;

How it can reach end(span(first, n+n))?
>

Not sure what you mean here.

> Perhaps we need whole new range category in order to make it efficient?

I don't think so.

> Or maybe just implement algorithms for counted ranges, which can take
> advantage of counted range, like Stepanov shows above?

Will look later, to see if I missed some points...

Thanks,


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