Boost logo

Boost Users :

Subject: [Boost-users] [Range] Sliced range adaptor, alternative for non RandomAccessRanges?
From: Alastair Rankine (arsptr_at_[hidden])
Date: 2011-01-25 01:22:30


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?

[1]:
http://www.boost.org/doc/libs/1_45_0/libs/range/doc/html/range/reference/adaptors/reference/sliced.html)


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