Boost logo

Boost Users :

Subject: Re: [Boost-users] [Random] Passing an arbitrary uniform random number generator to a function
From: Joseph Wakeling (joseph.wakeling_at_[hidden])
Date: 2010-04-27 07:02:31


Steven Watanabe wrote:
> A virtual function can't be a template.

... exactly my problem ... :-)

> You might be able to use something like this:
>
> template<class ResultType>
> class runtime_generator {
> public:
> ResultType min() const { return min_; }
> ResultType max() const { return max_; }
> ResultType operator()() { return impl(); }
> private:
> ResultType min_, max_;
> boost::function<ResultType()> impl;
> };

I'm sorry, I'm not sure I understand your suggestion. :-(

It's not clear to me how Boost's uniform random number generators
(URNGs) are meant to be passed around. I'm used to working with the GNU
Scientific Library where a URNG is simply a pointer that can be passed
around easily,

    void foo(gsl_rng *r)
    {
        // generate some numbers with r ...
    }

... where of course the particular URNG algorithm may vary.

By contrast it's not clear to me how, using Boost's random library, to
write code which uses a URNG without specifying its exact type -- unless
I use templates.

Can you advise?

Sorry for my lack of understanding of your suggestion.

Thanks & best wishes,

    -- Joe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net