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-30 12:50:49


I tried it out, yes you can get make_iterator_range with next to work. I
like boost::next but for what I wanted it does not seem to work
appropriately. Your example of "make_iterator_range(boost::next(b.begin,
wSize), v.end())" will only skip the first "wSize" elements. What I want
is a range that contains at most wSize elements (if possible) - taking them
from after (and containing) a start index.

Even my second attempt with this approach (commented out lines) does not
work because next does not check to see if it is past end. Perhaps if
there is a "min" method I could pass the "boost::next(v.begin() +
(start-1), window)" and "v.end()".

typedef vector<int> Vector;
Vector v = { 1, 2, 3, 4, 5, 6, 7, 8 , 9, 10, 11 };

cout << "--" << endl;
for(auto i : v) { cout << i << " "; }
cout << "\n--\n" << endl;

const int start = 10;
const int window = 4;

auto r = boost::make_iterator_range(boost::next(v.begin(), start-1),
v.end());
auto r2 = boost::make_iterator_range(boost::prior(r.end(), window),
r.end());

// auto r = boost::make_iterator_range(v.begin() + (start-1),
boost::next(v.begin() + (start-1), window) );
// auto r2 = boost::make_iterator_range(boost::prior(r.end(), window),
r.end());

cout << "\n--\nr: ";
for(auto i : r) { cout << i << " "; }

cout << "\n--\nr2: ";
for(auto i : r2) { cout << i << " "; }

cout << "\n--\n" << endl;

On Tue, Oct 30, 2012 at 1:18 AM, Neil Groves-3 [via Boost] <
ml-node+s2283326n4637772h7_at_[hidden]> wrote:

>
> On Tue, Oct 30, 2012 at 3:08 AM, David Kimmel <[hidden email]<http://user/SendEmail.jtp?type=node&node=4637772&i=0>
> > wrote:
>
>> 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!
>>
>>
>
> make_iterator_range is perfectly capable of meeting your expressed
> requirements. I have done this many times, I'm not hypothesising. Please
> see my original post. You just use boost::next to advance one of the
> iterators that define the range.
>
> See http://www.boost.org/doc/libs/1_51_0/libs/utility/utility.htm
>
> While respecting Thorsten's opinion and the wish to provide convenience
> functions to our users, I'm not keen on introducing make_iterator_range
> (iterator, size_type) it seems like an unnecessary addition that would not
> significantly improve syntax. It would also duplicate the logic behind
> boost::next within non-member functions in Boost.Range like
> make_iterator_range. I prefer orthogonal solutions and composition to
> duplication of the advance logic.
>
> Neil Groves
>
> _______________________________________________
> Boost-users mailing list
> [hidden email] <http://user/SendEmail.jtp?type=node&node=4637772&i=1>
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://boost.2283326.n4.nabble.com/Iterator-Range-sub-range-of-a-desired-size-tp4637719p4637772.html
> To unsubscribe from Iterator Range, sub range of a desired size, click
> here<http://boost.2283326.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4637719&code=ZGF2aWR3a2ltbWVsQGdtYWlsLmNvbXw0NjM3NzE5fC02MDQwMTk5NjU=>
> .
> NAML<http://boost.2283326.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>

--
View this message in context: http://boost.2283326.n4.nabble.com/Iterator-Range-sub-range-of-a-desired-size-tp4637719p4637789.html
Sent from the Boost - Users mailing list archive at Nabble.com.


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