Interest in bounded (Top-Bounded) Range adaptor.

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, The above example is similar in behavior to ... boost::copy_n( input, 0, std::ostream_iterator<int>(std::cout, ",")); boost::copy_n( input, 1, std::ostream_iterator<int>(std::cout, ",")); boost::copy_n( input, 2, std::ostream_iterator<int>(std::cout, ",")); boost::copy_n( input, 8, std::ostream_iterator<int>(std::cout, ",")); The difference is that *copy_n* algorithm doesn't check for begin(range) != end(range) In the following line, an error occurs at runtime... boost::copy_n( input, 9, std::ostream_iterator<int>(std::cout, ",")); Unlike the following that runs ok... boost::copy( input | bounded(9), std::ostream_iterator<int>(std::cout, ",")); // prints 1,2,3,4,5,7,8,9, This behavior could be equated using *sliced(0, X)*, but sliced requires *RandomAccessRange*, unlike bounded that requires *SinglePassRange*. *bounded* code is based on *indexed* adaptor code, I think it is more efficient than *sliced* ( that uses *make_iterator_range* --> std::advance ). I don't know if this behavior can be achieved using other adapters, if so, please let me know. Is there interest in this for Boost? Regards, Fernando.

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

On Fri, Oct 28, 2011 at 9:28 PM, Dave Abrahams <dave@boostpro.com> wrote:
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.
I think I have explained incorrectly. The above example is not appropriate. What I want to achieve ( using ranges ) is the following... //------------------------------------------------------- #include <iostream> #include <vector> #include <boost/assign.hpp> #include <boost/range/adaptors.hpp> int main() { using namespace boost::adaptors; using namespace boost::assign; std::vector<int> input; input += 0,1,1,2,3,5,8,13,21,34,55; auto it = boost::begin(input); auto end = boost::end(input); const int N = 9; // top bound for ( int i = 0; it != end && i < N; ++it, ++i ) { std::cout << *it << ','; // or whatever ... } } //------------------------------------------------------- // prints: 0,1,1,2,3,5,8,13,21, // ( 9 elements ) Similar to the algorithm *copy_n*, with the difference that *copy_n*doesn't check the end of the iterator. Perhaps "bound" isn't the best name, there should be a better name, maybe "top" ... I dont know... Could this behavior be replicated with other adaptors? Is the "until" adaptor part of Boost? Regards, Fernando.

Den 31-10-2011 13:17, Fernando Pelliccioni skrev:
On Fri, Oct 28, 2011 at 9:28 PM, Dave Abrahams<dave@boostpro.com> wrote:
Take a look at sliced: http://www.boost.org/doc/libs/1_45_0/libs/range/doc/html/range/reference/ada... we might need to generalize a little to allow non-random access ranges. -Thorsten

On Mon, Oct 31, 2011 at 9:52 AM, Thorsten Ottosen < thorsten.ottosen@dezide.com> wrote:
Den 31-10-2011 13:17, Fernando Pelliccioni skrev:
On Fri, Oct 28, 2011 at 9:28 PM, Dave Abrahams<dave@boostpro.com> wrote:
Take a look at sliced:
http://www.boost.org/doc/libs/**1_45_0/libs/range/doc/html/** range/reference/adaptors/**reference/sliced.html<http://www.boost.org/doc/libs/1_45_0/libs/range/doc/html/range/reference/adaptors/reference/sliced.html>
we might need to generalize a little to allow non-random access ranges.
I've seen *sliced* but it uses std::advance to begin() and end() iterators. The code I have doesn't require RandomAccessRange. Would you like to check it? Regards, Fernando.

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,
There is a Boost.Range extension library called P-stade Oven which provides this adaptor under the name "taken", and many other adaptors: http://p-stade.sourceforge.net/oven/doc/html/index.html There exists an effort to port the P-stade Oven library to Boost, called OvenToBoost: https://github.com/faithandbrave/OvenToBoost. If you are interested in seeing functionality like this in Boost, perhaps you can consider contributing to this effort. Regards, Nate

On Mon, Oct 31, 2011 at 12:31 PM, Nathan Ridge <zeratul976@hotmail.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,
There is a Boost.Range extension library called P-stade Oven which provides this adaptor under the name "taken", and many other adaptors:
http://p-stade.sourceforge.net/oven/doc/html/index.html
There exists an effort to port the P-stade Oven library to Boost, called OvenToBoost: https://github.com/faithandbrave/OvenToBoost. If you are interested in seeing functionality like this in Boost, perhaps you can consider contributing to this effort.
"taken" is what I was looking for. I will contact the project owners to offer my help. Thanks!! Regards, Fernando.

Hi, Fernando 2011/11/1 Fernando Pelliccioni <fpelliccioni@gmail.com>:
There exists an effort to port the P-stade Oven library to Boost, called OvenToBoost: https://github.com/faithandbrave/OvenToBoost. If you are interested in seeing functionality like this in Boost, perhaps you can consider contributing to this effort.
"taken" is what I was looking for. I will contact the project owners to offer my help.
I'm OvenToBoost author and Oven mantainer. OvenToBoost now status: - code : complete - documentation : incomplete. remain document is range-access, algorithm, regular operator(operator|+) rationale. Delay reason is weak my English and busy. I'm going documentation to help with some Japan members. I will to submit to Boost for review when document creation is complete.
======================== Akira Takahashi mailto:faithandbrave@gmail.com Blog: http://d.hatena.ne.jp/faith_and_brave/

On Mon, Oct 31, 2011 at 11:47 PM, Akira Takahashi <faithandbrave@gmail.com>wrote:
Hi, Fernando
There exists an effort to port the P-stade Oven library to Boost, called OvenToBoost: https://github.com/faithandbrave/OvenToBoost. If you are interested in seeing functionality like this in Boost,
2011/11/1 Fernando Pelliccioni <fpelliccioni@gmail.com>: perhaps
you can consider contributing to this effort.
"taken" is what I was looking for. I will contact the project owners to offer my help.
I'm OvenToBoost author and Oven mantainer. OvenToBoost now status: - code : complete - documentation : incomplete. remain document is range-access, algorithm, regular operator(operator|+) rationale.
Delay reason is weak my English and busy. I'm going documentation to help with some Japan members.
I will to submit to Boost for review when document creation is complete.
Hi Akira, Let me know if you need help. Regards, Fernando.

What about other Oven adaptors like "concatenated"?
boost/range/join.hpp ? (but undocument...)
I do not see a boost/range/join.hpp Am I looking in the right place? https://github.com/faithandbrave/OvenToBoost Thanks, Nate

I do not see a boost/range/join.hpp
Am I looking in the right place? https://github.com/faithandbrave/OvenToBoost
Sorry, I'm misunderstood as it is. concatednated range adaptor is "range of range" category. This design need more thinking... Was not included in the my first release. Do you want other "range of range" adaptor if include "range of range" category adaptor? (ex. oven::rows, oven::columns, etc...) Thanks, Akira
participants (5)
-
Akira Takahashi
-
Dave Abrahams
-
Fernando Pelliccioni
-
Nathan Ridge
-
Thorsten Ottosen