Boost logo

Boost Users :

Subject: Re: [Boost-users] Iterator Range, sub range of a desired size
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-10-30 15:12:23


> // 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!).
A hand-crafted solution could avoid this.

Regards,
Nate
                                               


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