|
Boost : |
From: Andy (atompkins_at_[hidden])
Date: 2007-06-13 16:47:35
"Jos Hickson" <jos.hickson_at_[hidden]> wrote in
news:fc03d05a0706120226n717d457fueca21627444a90d3_at_[hidden]:
< snip >
>> Really what we need is a Boost.Seed library to compliment
>> Boost.Random so that anybody like yourself using the latter doesn't
>> have to spend all this time wondering how to seed things generically.
I think that the seed class would be a good addition to Boost.Random.
< snip >
>> >
>> > template <typename Engine=boost::mt19937>
>> > class uuid_generator {
>> > public:
>> > uuid_generator() {
>> > boost::seed_rgn e;
>> > boost::generator_iterator<boost::seed_rng> begin(&e);
>> > boost::generator_iterator<boost::seed_rnd> end;
>> > en_.seed(begin, end);
>> > }
>> >
>> > boost::uuid operator()() {
>> > // get random data from en_
>> > // return uuid based on this data
>> > }
>> > private:
>> > Engine en_;
>> > };
>> >
>> > Now this works fine, the slow seed_rng is used to fully seed the
>> > random number generator used. It can be specialized for
>> > boost::random_device since boost::random_device does not have a
>> > seed function.
>> >
>> > Andy.
>> >
>>
So now I have this, and I like it, but I have been unable to use
boost::enable_if, and boost::disable_if to enable/disable the constructors.
template <typename Engine = boost::mt19937>
class basic_uuid_generator {
public:
// only enable if engine can not be seeded
// boost::random_device does not need seeding
basic_uuid_generator(/*enable only if Engine=boost::random_device*/)
{}
// enable if engine can be seeded
// seed engine
basic_uuid_generator(/*enable if Engine != boost::random_device*/)
{
boost::seed_rgn seed;
boost::generator_iterator<boost::seed_rng> begin(&seed);
boost::generator_iterator<boost::seed_rng> end;
en_.seed(begin, end);
}
// assume they have already seeded e and make a copy
// maybe we should store a reference to e?
explicit uuid_generator(Engine const& e)
: en_(e)
{}
boost::uuid operator()() { ... }
priavte:
Engine en_;
};
typedef basic_uuid_generator<> uuid_generator;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk