Boost logo

Boost Users :

Subject: Re: [Boost-users] [Range] Sliced range adaptor, alternative for non RandomAccessRanges?
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2011-01-26 08:35:26


Den 25-01-2011 07:22, Alastair Rankine skrev:
> Hi,
>
> Currently it seems that the sliced range adaptor [1] requires a Random
> Access Range to do its job. Hence it can't be used for other ranges
> which dont model this concept. I want to use it with a Forward Range,
> specifically a std::set iterator range.
>
> What I want to do is this:
>
> std::set<int> input;
> input += 1,2,3,4,5,6,7,8,9;
>
> boost::copy(
> input | sliced(2, 5),
> std::ostream_iterator<int>(std::cout, ","));
>
> (as per the sliced example, but with a std::set instead of a std::vector).
>
> I don't know much about the internals of the sliced adapter, but could
> it be changed to work a similar manner to counting_range, in order to
> locate the relevant slice of the input range? This would allow it to
> operate efficiently on Forward Ranges.
>
> Failing this, is there an efficient alternative to the above example?

make_iterator_range() have similar functionality.

I guess it would make sense to extend sliced() to
work in terms of advance() too, so it can work even with input iterators.

-Thorsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net