Boost logo

Boost Users :

Subject: Re: [Boost-users] Iterator Range, sub range of a desired size
From: Neil Groves (neil_at_[hidden])
Date: 2012-10-30 18:30:58


On Tue, Oct 30, 2012 at 7:12 PM, Nathan Ridge <zeratul976_at_[hidden]>wrote:

>
> > // 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



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