Boost logo

Boost :

Subject: [boost] [Generator Iterator] [random]
From: Andy Tompkins (atompkins_at_[hidden])
Date: 2008-10-15 13:35:12


I am trying to use boost::generator_iterator with a random number
generator as follows:

---
#include <boost/generator_iterator.hpp>
#include <boost/random/mersenne_twister.hpp>
class my_generator {...};
my_generator gen;
boost::generator_iterator<my_generator> first(&gen);
boost::generator_iterator<my_generator> last;
boost::random::mt19937 rng; rng.seed(first, last);
---
Sadly the default constructor of generator_iterator leaves m_gen
uninitialized and the seed function is trying to compare first
with last.
I could pass gen to last, ie. boost::generator_iterator<my_generator>
last(&gen), but then if ever begin has the same value as end, it
will stop.
The documentation for generator_iterator says that it models an input
iterator, and I assume that an input iterator is ok to use with the
seed function.
I'm not sure what can/should be done.
Thanks in advance,
  Andy.

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