Boost logo

Boost :

From: Anthony Williams (anthwil_at_[hidden])
Date: 2002-09-12 09:43:40

David Abrahams writes:
> From: "Anthony Williams" <anthwil_at_[hidden]>
> > David Abrahams writes:
> > > It would probably be easy to derive your Policies from the generator
> > > adaptor policies.
> >
> > I contemplated that, but it requires that the Generator class be
> callable,
> > which isn't going to be the case for the upper bound; to avoid this, the
> > policy class is sufficiently different to warrant being unrelated.
> >
> > Do you think it is a sufficiently common case to be worth adding to the
> > iterator adaptors library alongside generator_iterator?
> Sure, sounds good.

OK, I've uploaded it to:

It needs the StrongStorage class that I uploaded earlier. Usage is as for
generator_iterator, except that the generator is not invoked unless the
iterator is dereferenced, and the iterators compare equal if the generators
compare equal, rather than if they are both using the same generator. Here is
the example from the generator_iterator page, modified to use the bounded

#include <iostream>
#include "bounded_generator_iterator.hpp"

class my_generator
  typedef int result_type;
  my_generator() : state(0) { }
    my_generator(int i):
  int operator()() { return ++state; }

    friend bool operator==(const my_generator& lhs,const my_generator& rhs)
        return lhs.state==rhs.state;
  int state;

int main()
  my_generator gen,endgen(10);
          it = boost::make_bounded_generator_iterator(gen),
          end = boost::make_bounded_generator_iterator(endgen);
    std::cout << *it << std::endl;

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