On Tue, Oct 30, 2012 at 7:12 PM, Nathan Ridge
// General solution for all iterator types - assume that source here is v from your example auto r = boost::make_iterator_range( boost::next(boost::begin(source), start - 1), boost::next(boost::begin(source), std::min(start - 1 + window, static_cast<int>(boost::distance(source)))) );
I'm not seeing a problem. Am I misunderstanding your question?
The call to distance() will iterate over the range if it's not random-access (or worse, if it's an input range, it will consume it!).
I assume you mean SinglePassRange? We don't have none of those stinking conflated standard library concepts in Boost.Range! *lol* While it is true that my example was knowingly limited to working with ForwardRanges and above it was intended to be an unoptimised reasonably general example to ascertain understanding of the OPs requirements and his problem.
A hand-crafted solution could avoid this.
If you have a start index and a window it seemed pretty unlikely one would need anything other than support for RandomAccessRange to be honest. The context of the problem doesn't make much sense otherwise.
Regards, Nate
Cheers, Neil Groves