Boost logo

Boost :

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
  typedef int result_type;
  my_generator() : state(0) { }
  my_generator(int state_) : state(state_) { }
  int operator()() { return ++state; }
  int state;

int main()
    my_generator gen,endgen(11);
        it = ,
        end= ;


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)


Boost list run by bdawes at, gregod at, cpdaniel at, john at