Boost logo

Boost :

Subject: Re: [boost] Review Request : Boost.Range Extension
From: Akira Takahashi (faithandbrave_at_[hidden])
Date: 2012-05-29 23:17:35


Hi Michel,
Thanks for comment.

> [Infinite ranges]
> Boost.Iterator now has function_input_iterator which can be used
> to represent infinite ranges. IMHO, function_input_iterator is not so
> flexible and its implementation has some flaw:
> https://svn.boost.org/trac/boost/ticket/5825
> Oven's infinite range does not have such an issue, right?

iteration() function is OvenToBoost's infinite range.
This function's main purpose is makes number of sequence. But,
iteration() function can apply many case with other Range adaptors.
Past-the-end condition can specified taken/taken_while (and other adaptors).

basic past-the-end sample
#include <iostream>
#include <boost/range/algorithm/for_each.hpp>
#include <boost/range/iteration.hpp>
#include <boost/range/adaptor/taken_while.hpp>

int next_value(int x) { return x + 1; }
bool is_valid(int x) { return x < 10; }
void print(int x) { std::cout << x << " "; }

int main()
{
    using namespace boost::adaptors;

    boost::for_each(
      boost::iteration(0, next_value) | taken_while(is_valid), print);
}

// output:
// 0 1 2 3 4 5 6 7 8 9

#5825 alternative example:

#include <string>
#include <fstream>
#include <iostream>
#include <boost/range/algorithm/for_each.hpp>
#include <boost/range/iteration.hpp>
#include <boost/range/adaptor/taken.hpp>

static const std::string filename( "test.txt" );

struct generator {
    typedef int result_type;
    generator() : in(0) {}
    generator(std::ifstream& in) : in(&in) {}

    result_type operator() (int) {
        result_type ret;
        (*in) >> ret;
        return ret;
    }

    std::ifstream* in;
};

void print(int x) { std::cout << x << " "; }

int main()
{
    std::ofstream out(filename);
    out << 0 << std::endl
        << 1 << std::endl
        << 2 << std::endl
        << 3 << std::endl;

    std::ifstream in(filename);
    generator f(in);
    boost::for_each(boost::iteration(f(0), f) |
boost::adaptors::taken(3), print);
}

// output:
// 0 1 2

> [Incompatibilities between Boost.Range and Oven]
> Oven has some incompatibilities with Boost.Range.
> For example, boost::as_literal is not the same as oven::as_literal.
> It is oven::as_c_str that corresponds to boost::as_literal. To support
> these oven functions, we need to introduce breaking changes.

Now version, OvenToBoost not include as_literal/c_str.
I don't intend to introduce breaking change. This project is not full Oven.

> Boost.Range has recently changed size_type from signed to unsigned.
> (This is done only on trunk). Does this affect your library?

No affect.

Thanks,
Akira


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk