$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Anthony Williams (anthwil_at_[hidden])
Date: 2002-09-09 06:22:21
Is it possible to use boost iterator adaptors to generate a bounded sequence?
As an example, I will use a modified version of the boost::generator_iterator
example, which writes the numbers 1 to 10:
#include <iostream>
#include <iterator>
#include <algorithm>
#include <boost/some_iterator_adaptor_header.hpp>
class my_generator
{
public:
typedef int result_type;
my_generator() : state(0) { }
my_generator(int state_) : state(state_) { }
int operator()() { return ++state; }
private:
int state;
};
int main()
{
my_generator gen,endgen(11);
boost::some_iterator_adaptor_generator<my_generator>::type
it = ,
end= ;
std::copy(boost::make_some_iterator_adaptor(gen),
boost::make_some_iterator_adaptor(endgen),
std::ostream_iterator<int>(std::cout,"\n"));
}
In my actual usage, the generator does more than increase a state; the point
is I want to stop when I reach a defined condition (which can be encoded as
another instance of the generator if required)
Anthony