|
Boost : |
Subject: Re: [boost] Interest in bounded (Top-Bounded) Range adaptor.
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-10-28 20:28:00
on Thu Oct 27 2011, Fernando Pelliccioni <fpelliccioni-AT-gmail.com> wrote:
> Is there interest in adding a Top-Bounded adaptor into Boost.Range ?
>
> Example:
>
> using namespace boost::adaptors;
> using namespace boost::assign;
>
> std::vector<int> input;
> input += 1,2,3,4,5,6,7,8,9;
>
> boost::copy( input | bounded(0), std::ostream_iterator<int>(std::cout,
> ",")); // prints nothing
> boost::copy( input | bounded(1), std::ostream_iterator<int>(std::cout,
> ",")); // prints 1,
> boost::copy( input | bounded(2), std::ostream_iterator<int>(std::cout,
> ",")); // prints 1,2,
> boost::copy( input | bounded(8), std::ostream_iterator<int>(std::cout,
> ",")); // prints 1,2,3,4,5,7,8,
>
> Is there interest in this for Boost?
There is an obvious generalization that stops the range when a
predicate is satisfied, e.g.
boost::copy( input | until(_1 == 8),
std::ostream_iterator<int>(std::cout, ","));
That leads me to believe that the proper behavior of the
less-generalized component, which you call "bounded," is to stop the
range when the element reaches the bound, rather than including it.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk