Boost logo

Boost Users :

Subject: Re: [Boost-users] Iterator Range, sub range of a desired size
From: David Kimmel (davidwkimmel_at_[hidden])
Date: 2012-10-29 23:08:00


Whoa fast responses!

I like make_iterator_range and sliced but they don't quite seem to do it.
 Good point on the std::distance. No need to add a new make_iterator_range
- I may consider rethinking my approach or just leaving as is. Thanks
everyone!

On Mon, Oct 29, 2012 at 11:35 AM, Bill Buklis <boostusr_at_[hidden]> wrote:

> On 10/28/2012 11:40 PM, David Kimmel wrote:
>
>> Is there a function in BOOST, given a starting point and a desired size,
>> that
>> returns iterators for a (sub) range?
>>
>> For example, given:
>> a boost::circular_buffer which contains: 1 2 3 4 5 6 7 8 9 10
>> a starting point which is an iterator pointing to 5
>> and finally a desired size which is an int s = 4
>>
>> The result of which would be iterators producing: 5 6 7 8
>>
>> A possible implementation might be this (but I was hoping there was a
>> BOOST
>> version since I can't find an STD algorithm)
>>
>> template <typename Itr>
>> std::pair<Itr, Itr> getWindowDown(Itr begin, Itr end, Itr start, const int
>> windowSize)
>> {
>> // Down first, then up if need be
>> const Itr bottom = (end - start > windowSize) ? (start +
>> windowSize) :
>> (end);
>> const Itr top = (bottom - begin > windowSize) ? (bottom -
>> windowSize) :
>> (begin);
>> return make_pair(top, bottom);
>> }
>>
>>
>> Thanks,
>>
>>
> Would using next or advance work?
>
> For example, something like:
>
> range = std::make_pair(first, std::next(first, 4));
>
> I can't remember offhand if next is only c++11. If so, there might be a
> boost::next available. Or alternatively use advance, but it'll require an
> extra variable to hold the end iterator.
>
> Also, from a purely generic standpoint using std::distance is better than
> end - start.
>
> --
> Bill
>
> ______________________________**_________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/**mailman/listinfo.cgi/boost-**users>
>



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