[range] range library proposal implementation rev.2

Hi, all A new version of Oven, a range library proposal implementation, has been uploaded to Boost.Vault/Algorithm. The file: http://tinyurl.com/2axp2l Range Library Proposal: http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1871.html An example "infinite sequence of factorials": void test() { BOOST_AUTO(factorials, expression(counting(1, max_count)|scanned(1, regular(lambda::_1 * lambda::_2))) ); int const answer[] = { 1,1,2,6,24,120,720,5040,40320,362880 }; BOOST_CHECK( equals(factorials|taken(10), answer) ); } This library is highly preliminary, but moderately tested. Any feedback appreciated. Regards, -- Shunsuke Sogame

Excellent! I already use it. Thank you. On 7/15/07, shunsuke <pstade.mb@gmail.com> wrote:
Hi, all
A new version of Oven, a range library proposal implementation, has been uploaded to Boost.Vault/Algorithm.
The file: http://tinyurl.com/2axp2l
Range Library Proposal: http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1871.html
An example "infinite sequence of factorials":
void test() { BOOST_AUTO(factorials, expression(counting(1, max_count)|scanned(1, regular(lambda::_1 * lambda::_2))) );
int const answer[] = { 1,1,2,6,24,120,720,5040,40320,362880 }; BOOST_CHECK( equals(factorials|taken(10), answer) ); }
This library is highly preliminary, but moderately tested. Any feedback appreciated.
Regards,
-- Shunsuke Sogame
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

BTW, I suggest adding streambuf_writer and streambuf_reader only apply on the char_type, and read/write unformatted binary sequence. On 7/15/07, shunsuke <pstade.mb@gmail.com> wrote:
Hi, all
A new version of Oven, a range library proposal implementation, has been uploaded to Boost.Vault/Algorithm.
The file: http://tinyurl.com/2axp2l
Range Library Proposal: http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1871.html
An example "infinite sequence of factorials":
void test() { BOOST_AUTO(factorials, expression(counting(1, max_count)|scanned(1, regular(lambda::_1 * lambda::_2))) );
int const answer[] = { 1,1,2,6,24,120,720,5040,40320,362880 }; BOOST_CHECK( equals(factorials|taken(10), answer) ); }
This library is highly preliminary, but moderately tested. Any feedback appreciated.
Regards,
-- Shunsuke Sogame
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Atry wrote:
BTW, I suggest adding streambuf_writer and streambuf_reader only apply on the char_type, and read/write unformatted binary sequence.
Oven has streambuf_read and file_range. Also, the standard has std::ostreambuf_iterator. They are not enough? Regards, -- Shunsuke Sogame

Sorry, I have not seen streambuf_read one day before. I want to write a lazy encoder like utf_encoded, when I see your source, I found pstade.egg, it seems egg provider the base of your lisp like function, could you please add a little document for egg, I am realy interesting in the function style. On 8/16/07, shunsuke < pstade.mb@gmail.com> wrote:
Atry wrote:
BTW, I suggest adding streambuf_writer and streambuf_reader only apply on the char_type, and read/write unformatted binary sequence.
Oven has streambuf_read and file_range. Also, the standard has std::ostreambuf_iterator. They are not enough?
Regards,
-- Shunsuke Sogame
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Atry wrote:
Sorry, I have not seen streambuf_read one day before. I want to write a lazy encoder like utf_encoded, when I see your source, I found pstade.egg, it seems egg provider the base of your lisp like function, could you please add a little document for egg, I am realy interesting in the function style.
Egg is a set of higher-order functions which work with boost::result_of. Fortunately I'm now documenting Egg just for myself. :-) Though I cannot promise it, oven rev.3 might include the document. Regards, -- Shunsuke Sogame

When I use utf8_encoded, I am very strange that passing a wchar_t range to utf8_encoded is error on windows. You write BOOST_STATIC_ASSERT(sizeof(base_value_t)*CHAR_BIT == 32); But wchar_t is 16 bits length on windows. I have to write some like this: struct static_cast_to_u32 { typedef uint32_t result_type; result_type operator()(wchar_t c) const { return static_cast<result_type>(c); } }; u16_string | transformed(static_cast_to_u32()) | utf8_encoded; On 8/17/07, shunsuke <pstade.mb@gmail.com> wrote:
Atry wrote:
Sorry, I have not seen streambuf_read one day before. I want to write a lazy encoder like utf_encoded, when I see your source, I found pstade.egg, it seems egg provider the base of your lisp like function, could you please add a little document for egg, I am realy interesting in the function style.
Egg is a set of higher-order functions which work with boost::result_of. Fortunately I'm now documenting Egg just for myself. :-) Though I cannot promise it, oven rev.3 might include the document.
Regards,
-- Shunsuke Sogame
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

And I request for another feature: lexical_range. For example, if I need to generate a http request url, I would write: const char* host = "www.my-host.com"; unsinged short port = 8080; unsigned int id = 12345; new http_request("http://" | jointed(host) | jointed(single(':')) | jointed(lexical_cast<string>(port)) | jointed("/query?id=") | jointed(lexical_cast<string>(id))); All string operation are lazy but lexical_cast. If there is a lexical_range, I can write: new http_request("http://" | jointed(host) | jointed(single(':')) | jointed(make_lexical_range<char>(port)) | jointed("/query?id=") | jointed(make_lexical_range<char>(id))); The make_lexical_range will be faster than lexical_cast, and requires no heap allocate. On 8/17/07, Atry <pop.atry@gmail.com> wrote:
When I use utf8_encoded, I am very strange that passing a wchar_t range to utf8_encoded is error on windows. You write BOOST_STATIC_ASSERT(sizeof(base_value_t)*CHAR_BIT == 32); But wchar_t is 16 bits length on windows. I have to write some like this:
struct static_cast_to_u32 { typedef uint32_t result_type; result_type operator()(wchar_t c) const { return static_cast<result_type>(c); } };
u16_string | transformed(static_cast_to_u32()) | utf8_encoded;
On 8/17/07, shunsuke <pstade.mb@gmail.com> wrote:
Sorry, I have not seen streambuf_read one day before. I want to write a lazy encoder like utf_encoded, when I see your
Atry wrote: source, I
found pstade.egg, it seems egg provider the base of your lisp like function, could you please add a little document for egg, I am realy interesting in the function style.
Egg is a set of higher-order functions which work with boost::result_of. Fortunately I'm now documenting Egg just for myself. :-) Though I cannot promise it, oven rev.3 might include the document.
Regards,
-- Shunsuke Sogame
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Atry wrote:
All string operation are lazy but lexical_cast. If there is a lexical_range, I can write: new http_request("http://" | jointed(host) | jointed(single(':')) | jointed(make_lexical_range<char>(port)) | jointed("/query?id=") | jointed(make_lexical_range<char>(id)));
The make_lexical_range will be faster than lexical_cast, and requires no heap allocate.
I'm not sure how to implement such a range adaptor.
struct static_cast_to_u32 { typedef uint32_t result_type; result_type operator()(wchar_t c) const { return static_cast<result_type>(c); } };
u16_string | transformed(static_cast_to_u32()) | utf8_encoded;
In fact, that is a cut and paste from <boost/regex/pending/unicode_iterator.hpp>, so I don't understand it exactly. But that assertion seems a good practice. BTW, a null-terminated char pointer is no longer a range. See oven::as_c_str, as_literal and as_array. Regards, -- Shunsuke Sogame

shunsuke wrote:
Atry wrote:
All string operation are lazy but lexical_cast. If there is a lexical_range, I can write: new http_request("http://" | jointed(host) | jointed(single(':')) | jointed(make_lexical_range<char>(port)) | jointed("/query?id=") | jointed(make_lexical_range<char>(id)));
The make_lexical_range will be faster than lexical_cast, and requires no heap allocate.
I'm not sure how to implement such a range adaptor.
struct static_cast_to_u32 { typedef uint32_t result_type; result_type operator()(wchar_t c) const { return static_cast<result_type>(c); } };
u16_string | transformed(static_cast_to_u32()) | utf8_encoded;
In fact, that is a cut and paste from <boost/regex/pending/unicode_iterator.hpp>, so I don't understand it exactly. But that assertion seems a good practice.
BTW, a null-terminated char pointer is no longer a range. See oven::as_c_str, as_literal and as_array.
Regards,
I found that boost::oven::equals not support boost::iterator_range, Here is the test case. #define BOOST_AUTO_TEST_MAIN #include <boost/test/unit_test.hpp> #include <boost/oven/equals.hpp> #include <boost/oven/single.hpp> #include <boost/range/iterator_range.hpp> BOOST_AUTO_TEST_CASE(iterator_range_equals) { using namespace boost::oven; using namespace boost; using namespace std; stringstream ss("1"); BOOST_CHECK(equals(make_iterator_range(istreambuf_iterator<char>(ss), istreambuf_iterator<char>()), single('1'))); }

Atry wrote:
I found that boost::oven::equals not support boost::iterator_range, Here is the test case.
That is a STL implementation bug. istreambuf_iterator<>::reference is wrongly a reference type. Instead, you can use oven::streambuf_read that works around it. BOOST_CHECK(equals(streambuf_read(ss), single('1'))); Regards, -- Shunsuke Sogame

On 8/17/07, shunsuke <pstade.mb@gmail.com> wrote:
Atry wrote:
All string operation are lazy but lexical_cast. If there is a lexical_range, I can write: new http_request("http://" | jointed(host) | jointed(single(':')) | jointed(make_lexical_range<char>(port)) | jointed("/query?id=") | jointed(make_lexical_range<char>(id)));
The make_lexical_range will be faster than lexical_cast, and requires no heap allocate.
I'm not sure how to implement such a range adaptor.
What about hold a streambuf in a lexical_range? By the way that streambuf should be stack-based.
struct static_cast_to_u32 {
typedef uint32_t result_type; result_type operator()(wchar_t c) const { return static_cast<result_type>(c); } };
u16_string | transformed(static_cast_to_u32()) | utf8_encoded;
In fact, that is a cut and paste from <boost/regex/pending/unicode_iterator.hpp>, so I don't understand it exactly. But that assertion seems a good practice.
Ah, it seems that you forget to copy u16_to_u32_iterator... BTW, a null-terminated char pointer is no longer a range.
See oven::as_c_str, as_literal and as_array.
Regards,
-- Shunsuke Sogame
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Atry wrote:
What about hold a streambuf in a lexical_range? By the way that streambuf should be stack-based.
I'm still not sure how. BTW, I bet a stream construction is slower than lexical_cast<string> under Boost1.35.
Ah, it seems that you forget to copy u16_to_u32_iterator...
It will be added sooner or later. :-) Regards, -- Shunsuke Sogame
participants (2)
-
Atry
-
shunsuke