Boost logo

Boost :

Subject: Re: [boost] [UUID] version v12
From: Andy Tompkins (atompkins_at_[hidden])
Date: 2008-10-16 22:11:24


Hi Johannes,

On Mon, 13 Oct 2008 13:12:02 +0200, "Johannes Brunen"
<JBrunen_at_[hidden]> said:
> Hello Andy,
>
> after some investigations, I think that I have found the origin of the
> problem:
>
> In seed_rng.hpp the following code is used:
>
> template <typename UniformRandomNumberGenerator>
> inline void seed(UniformRandomNumberGenerator& rng)
> {
> seed_rng seed_gen;
> boost::generator_iterator<seed_rng> begin(&seed_gen);
> boost::generator_iterator<seed_rng> end;
> rng.seed(begin, end);
> }
>
> Problematic is the construction of the end iterator. Looking into the
> code
> (boost/generator_iterator.hpp) shows, that the default constructor of
> generator_iterator does not initialize its member variables.
>
> generator_iterator() {}
>
> Howerver, the mersenne_twister seed code does compare the two given
> iterators as shown below (boost/random/).
>
> template<class It>
> void seed(It& first, It last)
> {
> int j;
> for(j = 0; j < n && first != last; ++j, ++first)
> x[j] = *first;
> i = n;
> if(first == last && j < n)
> throw std::invalid_argument("mersenne_twister::seed");
> }
>
> As the end iterator is not initialized the way is open for all throwing
> the
> invalid_argument exception.
>
> Locally, I did solve the problem by patching the default constructor of
> class generator_iterator.
>
> If this is a valid solution of the problem, it would be fine if anyone
> applies the correction to the boost code.
>
> Greetings,
> Johannes
>

I have put a new version in the boost vault.
http://www.boostpro.com/vault/index.php?action=downloadfile&filename=uuid_v13.zip&directory=&
It addresses this problem by making a copy of boost::generator_iterator
with your fix.

Regards,
  Andy.


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